-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
trait_duplication_in_bounds
lint doesn't consider generics
#8757
Comments
trait_duplication_in_bounds
lint doesn't consider generics
rust-lang/rust-clippy#8757 error: this trait bound is already specified in the where clause --> tests/regression/issue845.rs:13:8 | 13 | T: TryFrom<u64> + TryFrom<i64> + FromStr, | ^^^^^^^^^^^^ | = note: `-D clippy::trait-duplication-in-bounds` implied by `-D clippy::pedantic` = help: consider removing this trait bound = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trait_duplication_in_bounds error: this trait bound is already specified in the where clause --> tests/regression/issue845.rs:14:33 | 14 | <T as TryFrom<u64>>::Error: Display, | ^^^^^^^ | = help: consider removing this trait bound = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trait_duplication_in_bounds error: this trait bound is already specified in the where clause --> tests/regression/issue845.rs:49:8 | 49 | T: TryFrom<u64> + TryFrom<i64> + FromStr, | ^^^^^^^^^^^^ | = help: consider removing this trait bound = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trait_duplication_in_bounds error: this trait bound is already specified in the where clause --> tests/regression/issue845.rs:50:33 | 50 | <T as TryFrom<u64>>::Error: Display, | ^^^^^^^ | = help: consider removing this trait bound = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trait_duplication_in_bounds
Here are some more test cases for this issue: #![warn(clippy::trait_duplication_in_bounds)]
trait Trait<A> {}
struct Foo;
// to avoid trivial bound lint
impl Trait<u8> for Foo {}
impl Trait<i8> for Foo {}
impl Trait<u8> for () {}
impl Trait<i8> for () {}
fn ok1() where Foo: Trait<u8> + Trait<i8> {}
fn bad2<A>() where Foo: Trait<u8> + Trait<i8> {} // bad
fn ok3<A>() where (): Trait<u8> + Trait<i8> {}
fn bad3<A>() where Foo: Trait<A> + Trait<i8> {} // bad
fn bad4<A, B>() where Foo: Trait<A> + Trait<B> {} // bad
impl<A> Trait<(A,)> for Foo where Foo: Trait<A> + Trait<u8> {} // bad
impl<A, B> Trait<(A, B)> for Foo where Foo: Trait<A> + Trait<B> {} // bad
fn main() {} |
I've been poking at this problem since it is related to my PR. ReproducerI tried this code: fn duplicate_trait<T: Clone + Clone + Default, Z: Copy>(arg0: T, arg1: Z) {} I saw this happen:
The error message always says Two interpretations.
|
Based on the example in the lint's docs, I think the behavior is unexpected. Point 1 makes more sense, imo |
- only compare where predicates to trait bounds when generating where clause specific message to fix rust-lang#9151 - use comparable_trait_ref to account for trait bound generics to fix rust-lang#8757
- only compare where predicates to trait bounds when generating where clause specific message to fix rust-lang#9151 - use comparable_trait_ref to account for trait bound generics to fix rust-lang#8757
- only compare where predicates to trait bounds when generating where clause specific message to fix rust-lang#9151 - use comparable_trait_ref to account for trait bound generics to fix rust-lang#8757
rust-lang/rust-clippy#8757 error: this trait bound is already specified in the where clause --> tests/regression/issue845.rs:13:8 | 13 | T: TryFrom<u64> + TryFrom<i64> + FromStr, | ^^^^^^^^^^^^ | = note: `-D clippy::trait-duplication-in-bounds` implied by `-D clippy::pedantic` = help: consider removing this trait bound = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trait_duplication_in_bounds error: this trait bound is already specified in the where clause --> tests/regression/issue845.rs:14:33 | 14 | <T as TryFrom<u64>>::Error: Display, | ^^^^^^^ | = help: consider removing this trait bound = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trait_duplication_in_bounds error: this trait bound is already specified in the where clause --> tests/regression/issue845.rs:49:8 | 49 | T: TryFrom<u64> + TryFrom<i64> + FromStr, | ^^^^^^^^^^^^ | = help: consider removing this trait bound = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trait_duplication_in_bounds error: this trait bound is already specified in the where clause --> tests/regression/issue845.rs:50:33 | 50 | <T as TryFrom<u64>>::Error: Display, | ^^^^^^^ | = help: consider removing this trait bound = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trait_duplication_in_bounds
Summary
@giraffate caught this issue in #8703 PR which is based on the TRAIT_DUPLICATION_IN_BOUNDS lint.
Lint Name
TRAIT_DUPLICATION_IN_BOUNDS
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
No linting error as while the same trait is used, the concrete type argument it is applied to is different.
Version
The text was updated successfully, but these errors were encountered: