-
-
Notifications
You must be signed in to change notification settings - Fork 17.2k
Add a lint for equality bounds on generic parameters #21684
Copy link
Copy link
Closed
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Description
Activity
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Since a lot of traits now use associated types, some code can be simplified, removing the need for some generic parameters. However, some code may not utilise this flexibility, treating associated types in the same way as usual type parameters (especially if the trait was only recently changed to use associated types, and code like
Trait<T>was simply changed toTrait<Foo=T>). For example:I think a lint could detect these redundant type parameters by warning whenever a type parameter is equated with anything in an equality bound. In other words, I think
T = AnyTypeis always indicative of an unnecessary type parameter (although I’m not 100% sure on this—is there any example where that’s a valid thing to do?).