Skip to content

Fix: #17783 useless_attribute false positive fixed - #17787

Open
GauravPawar101 wants to merge 1 commit into
rust-lang:masterfrom
GauravPawar101:fix-useless-attribute-allow-attributes
Open

GauravPawar101 wants to merge 1 commit into
rust-lang:masterfrom
GauravPawar101:fix-useless-attribute-allow-attributes

Conversation

@GauravPawar101

@GauravPawar101 GauravPawar101 commented Sep 26, 2026 •

Copy link
Copy Markdown

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:

#[allow(unused_imports)]          // Hits allowlist, returns early
#[allow(clippy::almost_swapped)]  // Never evaluated (false negative)
Swapping those two lines made the lint suddenly fire on almost_swapped.

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!?

@rustbot rustbot added S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Sep 26, 2026
@rustbot

rustbot commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

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.

@rustbot

rustbot commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

@CommanderStorm

This comment was marked as resolved.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Sep 26, 2026
@rustbot

rustbot commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Sep 26, 2026
@GauravPawar101

Copy link
Copy Markdown
Author

@rustbot ready

@CommanderStorm CommanderStorm left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

View changes since this review

@@ -0,0 +1,29 @@
//@no-rustfix
#![warn(clippy::useless_attribute)]
#![feature(rustc_private)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why rustc_private?

// checked on their own.
let is_meaningful = lint_list
.iter()
.any(|lint| is_emitted_on_item(item, lint, skip_unused_imports));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 😉

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤔
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment on lines +173 to +174
// don't lint on clippy::allow_attributes for `use` items, the documented workaround for
// https://github.com/rust-lang/rust-clippy/issues/17562

@CommanderStorm CommanderStorm Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Curious: Documented where btw?

View changes since the review

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. 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.

clippy::useless_attribute incorrectly flags clippy::allow_attributes on use (itself needed for things like allow(unused_imports))

3 participants