Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dbg_macro] tolerates use of dbg! in items which have #[cfg(test)] attribute #8838

Merged
merged 2 commits into from
May 19, 2022

Conversation

tamaroning
Copy link
Contributor

@tamaroning tamaroning commented May 17, 2022

fix: #8758
changelog: [dbg_macro] tolerates use of dbg! in items with #[cfg(test)] attribute

@rust-highfive
Copy link

r? @flip1995

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 17, 2022
@tamaroning tamaroning marked this pull request as ready for review May 17, 2022 16:17
@xFrednet
Copy link
Member

xFrednet commented May 17, 2022

r? @Jarcho 🙃

@xFrednet xFrednet self-assigned this May 17, 2022
Copy link
Contributor

@Jarcho Jarcho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. Just two little style related nits.

if attr.has_name(sym::cfg)
&& let Some(items) = attr.meta_item_list()
&& items.len() == 1
&& items[0].has_name(sym::test)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit. This could be let [item] = &*items && item.has_name(sym::test).

}
tcx.hir()
.parent_iter(id)
.any(|(parent_id, _)| tcx.hir().attrs(parent_id).iter().any(is_cfg_test))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit. This could be flat_map(|(parent_id, _)| tcx.hir().attrs(parent_id)).any(is_cfg_test).

@tamaroning
Copy link
Contributor Author

@Jarcho
Thank you for your review. I fixed them.

Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. I'll leave the final r+ to @Jarcho

@Jarcho when you merge, it would be cool if you could use r=Jarcho,xFrednet 🙃

@xFrednet
Copy link
Member

@bors delegate=Jarcho

(Bors doesn't work in review comments)

@bors
Copy link
Collaborator

bors commented May 19, 2022

✌️ @Jarcho can now approve this pull request

@Jarcho
Copy link
Contributor

Jarcho commented May 19, 2022

Everything looks good. @bors r=Jarcho,xFrednet

@bors
Copy link
Collaborator

bors commented May 19, 2022

📌 Commit db41df1 has been approved by Jarcho,xFrednet

@bors
Copy link
Collaborator

bors commented May 19, 2022

⌛ Testing commit db41df1 with merge ea96091...

@bors
Copy link
Collaborator

bors commented May 19, 2022

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Jarcho,xFrednet
Pushing ea96091 to master...

@bors bors merged commit ea96091 into rust-lang:master May 19, 2022
@afetisov
Copy link

That is now a very confusing behaviour on the part of that lint. When I run it, I expect it to find all uses of dbg, regardless of test or no test. When I use dbg in tests, it's also for debugging purposes, and leaving it in will just cause tests to spam debug messages in the console.

A change like that should have been a separate lint with a clear name, which could be separately allowed.

@xFrednet
Copy link
Member

xFrednet commented May 26, 2022

I would dislike splitting the lint, but we could introduce a config value, which enables the user to specify the behavior in tests. Do you think that is a better idea? @afetisov 🙃

@afetisov
Copy link

I don't have any objections to a config value, I would just want the lint to be enabled everywhere by default.

@afetisov
Copy link

I think a separate lint is a bit better for discoverability, since Clippy will print its name when it triggers. Config values are afaik mentioned only in the docs. But from a practical perspective, a config value indeed makes more sense.

@xFrednet
Copy link
Member

The question would be how the lints, should be split. It wouldn't make sense to have one lint that tests everything and one that is specific to anything but functions, as they would overlap. Therefore, we would need one lint for tests and one for other code. For me, that would be more confusing than a config value. But I'm also used to working with the lint list ^^

@tamaroning
Copy link
Contributor Author

tamaroning commented May 26, 2022

I think it is better to introduce a config value and to warn all dbg! by default too. Mentioning it in warning messages of [dbg_macro] might be useful.

@xFrednet
Copy link
Member

Would you mind adding it? We have some documentation how this can be done. If not, we can just create a new issue 🙃

@tamaroning
Copy link
Contributor Author

Okey. I will take care of it

@tamaroning tamaroning deleted the fix_dbg branch May 26, 2022 16:45
bors added a commit that referenced this pull request May 27, 2022
Introduce `allow-dbg-in-tests` config value

related to: Issue #8758,  PR #8838

changelog: Introduced `allow-dbg-in-tests` config value. [dbg_macro] does not allow `dbg!` in test code by default.
fabricedesre pushed a commit to capyloon/arti that referenced this pull request Jun 3, 2022
This was done because Nightly Rust complained about these, despite
them all being in tests.  That is now fixed upstream:
  rust-lang/rust-clippy#8758
  rust-lang/rust-clippy#8838

This reverts commit 9d26a91.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dbg-macro should tolerate use of dbg! in tests (redux, even with --tests)
7 participants