Open alice-i-cecile opened 3 months ago
If you want to get fancy with it, you could add a check for implied duplicate bounds, e.g. Hash implies PartialEq, so trait Foo: Hash + PartialEq is pointless.
We might be able to use some of the logic in the implied_bounds_in_impls
lint for this.
I don't think Hash
implies PartialEq
, but for example that lint already understands & warns on fn f() -> impl Copy + Clone { 1 }
because trait Copy: Clone {}
, so this feels like it could share a lot of logic.
Ah right, it's not actually implied, just used by the derive macro 😅
What it does
Checks for traits that are bounded by the same trait more than once.
If you want to get fancy with it, you could add a check for implied duplicate bounds, e.g.
Hash
impliesPartialEq
, sotrait Foo: Hash + PartialEq
is pointless.This was detected in https://github.com/Leafwing-Studios/leafwing-input-manager/pull/545.
Playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e298f6d998b87fe37663e1df073297f4
Advantage
These duplicate bounds are pointless and confusing.
Drawbacks
The more advanced implied redundant trait bound detection could reduce clarity of the code, and is less robust to future refactoring of the traits being relied on, as bounds may be removed in the future.
Example
Could be written as: