-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Add lint_duplicate_trait
for duplicate specified traits in a trait object
#110991
Conversation
r? @lcnr (rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
||
let mut bounds = (*bounds).to_owned(); | ||
|
||
bounds.sort_unstable_by_key(|b| b.trait_ref.trait_def_id()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DefIds are not stable across compilations and should not be used for sorting like here. Instead of what you're doing right now, you should use a FxHashSet
and iterate through the bounds (in source order) and insert their def ids into the set. If a def id is already in the set, emit the lint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will make that change. Out of curiosity, why does the fact they're unstable across compilations matter? The only aim of the sort is to group like DefId
s together, which should still be valid given it is within one compilation right?
Shouldn't https://rust-lang.github.io/rust-clippy/master/#trait_duplication_in_bounds be extended instead? |
The job Click to see the possible cause of the failure (guessed by this bot)
|
Thanks, have moved to rust-lang/rust-clippy#10727 |
Extend `trait_duplication_in_bounds` to cover trait objects This PR extends `trait_duplication_in_bounds` to cover trait objects. Currently, ```rs fn foo(_a: &(dyn Any + Send + Send)) {} ``` generates no warnings. With this PR, it will complain about a duplicate trait and can remove it Moved from rust-lang/rust#110991 changelog: [`trait_duplication_in_bounds`]: warn on duplicate trait object constraints
This adds a new lint,
lint_duplicate_traits
, which warns when traits are duplicately specified, which currently produces no diagnostics.Related to #110961