rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

Lint inline trait bounds in favor of `where` bounds

Open jhpratt opened this issue 10 months ago • 4 comments

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 where bound)
  • 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::restriction group). 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.

jhpratt avatar Jan 28 '26 05:01 jhpratt

@rustbot claim

moses7054 avatar Jan 28 '26 10:01 moses7054

@moses7054 I noticed there hasn’t been any progress on this for two weeks. Would it be alright if I give it a try?

zayutaha avatar Feb 24 '26 07:02 zayutaha

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.

moses7054 avatar Feb 24 '26 07:02 moses7054

Good luck!

zayutaha avatar Feb 24 '26 09:02 zayutaha