Fix: #17783 useless_attribute false positive fixed - #17787
GauravPawar101 wants to merge 1 commit into
Conversation
|
Thanks for the pull request, and welcome! You should hear from one of our reviewers after this PR gets at least 2 reviews from the community. Please see the contribution instructions for more information. |
|
This comment was marked as resolved.
This comment was marked as resolved.
|
Reminder, once the PR becomes ready for a review, use |
|
@rustbot ready |
There was a problem hiding this comment.
Thanks for the response 😆
Community review: mostly LGTM with two questions
For the future (or now, if you have the time) please split this up into one refactoring and one bugfixing commit, since reviewing both code movement, code refactorigns and code fixes is kind of bug prown.
The me figuring out what moved/refactored/changed for every reviewer is kind of unnessary 😉
I also attached two questions about the tests and one refactoring request, both should be simple to answer
| @@ -0,0 +1,29 @@ | |||
| //@no-rustfix | |||
| #![warn(clippy::useless_attribute)] | |||
| #![feature(rustc_private)] | |||
| // checked on their own. | ||
| let is_meaningful = lint_list | ||
| .iter() | ||
| .any(|lint| is_emitted_on_item(item, lint, skip_unused_imports)); |
There was a problem hiding this comment.
I feel this can be written a bit clearer and more like you intened.
Can you push the ! down into the function? I feel it would increase the clarity a lot 😉
There was a problem hiding this comment.
🤔
There must be a reason for this, but it is not entirely obvious from looking at the code.
Why is this here and not in am mod issue17783 in uselses_attributes.rs
| pub use f::deprec; | ||
| } | ||
|
|
||
| // don't lint on clippy::allow_attributes for `use` items, the documented workaround for |
There was a problem hiding this comment.
please wrap this in an mod issue17562 like above code.
This makes future authors more sure which parts belong to what issue to read more
| // don't lint on clippy::allow_attributes for `use` items, the documented workaround for | ||
| // https://github.com/rust-lang/rust-clippy/issues/17562 |
There was a problem hiding this comment.
Curious: Documented where btw?
Fixes #17783
useless_attribute was short-circuiting whole items. As soon as it hit a permitted attribute or macro check, a bare return bailed on the rest of the item, leaving subsequent attributes completely unchecked.
Because of this early return, source order mattered:
Fix
Evaluated per-attribute instead of per-item: Extracted is_emitted_on_item and moved the external-macro check inline so processing continues past allowed attributes.
Expanded the allowlist: With early returns fixed, added clippy::allow_attributes, clippy::useless_attribute (self-suppression), and exported_private_dependencies.
Tests: Added tests/ui/useless_attribute_order.rs covering order permutations for use and extern crate.
changelog: [useless_attribute]: fix false positive/negative pair caused by early-return in the attribute-allowlist check
em dashes were just a force of habit and were for clear separation and emphasizing!?