rust-clippy
rust-clippy copied to clipboard
Lint inline trait bounds in favor of `where` bounds
What it does
enforce that where bounds are used for all trait bounds
Advantage
- Enforce a single style throughout a codebase
- Avoid uncertainty about whether a bound should be inline or out-of-line (i.e. a
wherebound) - Avoid complex inline bounds, making a function declaration more difficult to read
Drawbacks
- Avoiding inline bounds for simple cases (such as
T: Clone) could be considered unidiomatic. - If the converse is also added, some people will inevitable enable both lints (such as via the
clippy::restrictiongroup). I do not view this as an issue given it is clearly a stylistic preference and the pre-existing presence of conflicting options.
Example
fn foo<T: Clone>() {}
Could be written as:
fn foo<T>() where T: Clone {}
Comparison with existing lints
From a quick search, I did not find anything like this.
Additional Context
For obvious reasons, this would be in the restriction group and allow-by-default.
@rustbot claim
@moses7054 I noticed there hasn’t been any progress on this for two weeks. Would it be alright if I give it a try?
hi @zayutaha i did a pr #16486 . The scope was expanded a bit and i am working on that. I was little stuck. if i am not able to complete it, I will unasign myself so that you can pick it up.
Good luck!