Closed
Description
Lint Name
type_repetition_in_bounds
Reproducer
# .clippy.toml
msrv = "1.14.0"
// lib.rs
pub trait Trait<X, Y, Z> {}
pub fn f<T: ?Sized, U>(arg: usize)
where
T: Trait<Option<usize>, Box<[String]>, bool> + 'static,
U: Clone + Sync + 'static,
{}
error: this type has already been used as a bound predicate
--> src/lib.rs:7:5
|
7 | T: Trait<Option<usize>, Box<[String]>, bool> + 'static,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::type-repetition-in-bounds` implied by `-D clippy::pedantic`
= help: consider combining the bounds: `T: Sized + Trait<Option<usize>, Box<[String]>, bool>`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds
Clippy prefers I guess one of the following signatures instead:
pub fn f<T, U>(arg: usize)
where
T: ?Sized + Trait<Option<usize>, Box<[String]>, bool> + 'static,
U: Clone + Sync + 'static
// or:
pub fn f<T: ?Sized + Trait<Option<usize>, Box<[String]>, bool> + 'static, U>(arg: usize)
where
U: Clone + Sync + 'static
The first one is great on modern compilers, but is a parse error on Rust 1.14 and older. Meanwhile, the second is not an improvement in my opinion. The bounds next to a type parameter (as opposed to in a where-clause) are only meant to be used for small/simple bounds.
I believe clippy should not trigger type_repetition_in_bounds if the msrv is declared as 1.14.0 or older and the type parameter has a single bound of ?Sized
, with all the rest of the bounds being in the where-clause.
Version
rustc 1.62.0-nightly (7c4b47696 2022-04-30)
binary: rustc
commit-hash: 7c4b47696907d64eff5621a64eb3c6e795a9ec77
commit-date: 2022-04-30
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.1
Additional Labels
No response