mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-15 01:17:16 +00:00
8c48b936cc
[`implied_bounds_in_impls`]: include (previously omitted) associated types in suggestion Fixes #11435 It now includes associated types from the implied bound that were omitted in the second bound. Example: ```rs fn f() -> impl Iterator<Item = u8> + ExactSizeIterator> {..} ``` Suggestion before this change: ```diff - pub fn my_iter() -> impl Iterator<Item = u32> + ExactSizeIterator { + pub fn my_iter() -> impl ExactSizeIterator { ``` It didn't include `<Item = u32>` on `ExactSizeIterator`. Now, with this change, it does. ```diff - pub fn my_iter() -> impl Iterator<Item = u32> + ExactSizeIterator { + pub fn my_iter() -> impl ExactSizeIterator<Item = u32> { ``` We also now extend the span to include not just possible `+` ahead of it, but also behind it (an example for this is in the linked issue as well). **Note:** The overall diff is a bit noisy, because building up the suggestion involves quite a bit more logic now and I decided to extract that into its own function. For that reason, I split this PR up into two commits. The first commit contains the actual "logic" changes. Second commit just moves code around. changelog: [`implied_bounds_in_impls`]: include (previously omitted) associated types in suggestion changelog: [`implied_bounds_in_impls`]: include the `+` behind bound if it's the last bound
196 lines
7.4 KiB
Text
196 lines
7.4 KiB
Text
error: this bound is already specified as the supertrait of `DerefMut<Target = T>`
|
|
--> $DIR/implied_bounds_in_impls.rs:13:36
|
|
|
|
|
LL | fn deref_derefmut<T>(x: T) -> impl Deref<Target = T> + DerefMut<Target = T> {
|
|
| ^^^^^^^^^^^^^^^^^
|
|
|
|
|
= note: `-D clippy::implied-bounds-in-impls` implied by `-D warnings`
|
|
= help: to override `-D warnings` add `#[allow(clippy::implied_bounds_in_impls)]`
|
|
help: try removing this bound
|
|
|
|
|
LL - fn deref_derefmut<T>(x: T) -> impl Deref<Target = T> + DerefMut<Target = T> {
|
|
LL + fn deref_derefmut<T>(x: T) -> impl DerefMut<Target = T> {
|
|
|
|
|
|
|
error: this bound is already specified as the supertrait of `GenericSubtrait<U, W, U>`
|
|
--> $DIR/implied_bounds_in_impls.rs:30:37
|
|
|
|
|
LL | fn generics_implied<U, W>() -> impl GenericTrait<W> + GenericSubtrait<U, W, U>
|
|
| ^^^^^^^^^^^^^^^
|
|
|
|
|
help: try removing this bound
|
|
|
|
|
LL - fn generics_implied<U, W>() -> impl GenericTrait<W> + GenericSubtrait<U, W, U>
|
|
LL + fn generics_implied<U, W>() -> impl GenericSubtrait<U, W, U>
|
|
|
|
|
|
|
error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, V>`
|
|
--> $DIR/implied_bounds_in_impls.rs:36:40
|
|
|
|
|
LL | fn generics_implied_multi<V>() -> impl GenericTrait<i32> + GenericTrait2<V> + GenericSubtrait<(), i32, V> {}
|
|
| ^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: try removing this bound
|
|
|
|
|
LL - fn generics_implied_multi<V>() -> impl GenericTrait<i32> + GenericTrait2<V> + GenericSubtrait<(), i32, V> {}
|
|
LL + fn generics_implied_multi<V>() -> impl GenericTrait2<V> + GenericSubtrait<(), i32, V> {}
|
|
|
|
|
|
|
error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, V>`
|
|
--> $DIR/implied_bounds_in_impls.rs:36:60
|
|
|
|
|
LL | fn generics_implied_multi<V>() -> impl GenericTrait<i32> + GenericTrait2<V> + GenericSubtrait<(), i32, V> {}
|
|
| ^^^^^^^^^^^^^^^^
|
|
|
|
|
help: try removing this bound
|
|
|
|
|
LL - fn generics_implied_multi<V>() -> impl GenericTrait<i32> + GenericTrait2<V> + GenericSubtrait<(), i32, V> {}
|
|
LL + fn generics_implied_multi<V>() -> impl GenericTrait<i32> + GenericSubtrait<(), i32, V> {}
|
|
|
|
|
|
|
error: this bound is already specified as the supertrait of `GenericSubtrait<(), T, V>`
|
|
--> $DIR/implied_bounds_in_impls.rs:38:44
|
|
|
|
|
LL | fn generics_implied_multi2<T, V>() -> impl GenericTrait<T> + GenericTrait2<V> + GenericSubtrait<(), T, V>
|
|
| ^^^^^^^^^^^^^^^
|
|
|
|
|
help: try removing this bound
|
|
|
|
|
LL - fn generics_implied_multi2<T, V>() -> impl GenericTrait<T> + GenericTrait2<V> + GenericSubtrait<(), T, V>
|
|
LL + fn generics_implied_multi2<T, V>() -> impl GenericTrait2<V> + GenericSubtrait<(), T, V>
|
|
|
|
|
|
|
error: this bound is already specified as the supertrait of `GenericSubtrait<(), T, V>`
|
|
--> $DIR/implied_bounds_in_impls.rs:38:62
|
|
|
|
|
LL | fn generics_implied_multi2<T, V>() -> impl GenericTrait<T> + GenericTrait2<V> + GenericSubtrait<(), T, V>
|
|
| ^^^^^^^^^^^^^^^^
|
|
|
|
|
help: try removing this bound
|
|
|
|
|
LL - fn generics_implied_multi2<T, V>() -> impl GenericTrait<T> + GenericTrait2<V> + GenericSubtrait<(), T, V>
|
|
LL + fn generics_implied_multi2<T, V>() -> impl GenericTrait<T> + GenericSubtrait<(), T, V>
|
|
|
|
|
|
|
error: this bound is already specified as the supertrait of `GenericSubtrait<(), i32, ()>`
|
|
--> $DIR/implied_bounds_in_impls.rs:48:28
|
|
|
|
|
LL | fn generics_same() -> impl GenericTrait<i32> + GenericSubtrait<(), i32, ()> {}
|
|
| ^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: try removing this bound
|
|
|
|
|
LL - fn generics_same() -> impl GenericTrait<i32> + GenericSubtrait<(), i32, ()> {}
|
|
LL + fn generics_same() -> impl GenericSubtrait<(), i32, ()> {}
|
|
|
|
|
|
|
error: this bound is already specified as the supertrait of `DerefMut<Target = u8>`
|
|
--> $DIR/implied_bounds_in_impls.rs:52:20
|
|
|
|
|
LL | fn f() -> impl Deref + DerefMut<Target = u8>;
|
|
| ^^^^^
|
|
|
|
|
help: try removing this bound
|
|
|
|
|
LL - fn f() -> impl Deref + DerefMut<Target = u8>;
|
|
LL + fn f() -> impl DerefMut<Target = u8>;
|
|
|
|
|
|
|
error: this bound is already specified as the supertrait of `DerefMut<Target = u8>`
|
|
--> $DIR/implied_bounds_in_impls.rs:57:20
|
|
|
|
|
LL | fn f() -> impl Deref + DerefMut<Target = u8> {
|
|
| ^^^^^
|
|
|
|
|
help: try removing this bound
|
|
|
|
|
LL - fn f() -> impl Deref + DerefMut<Target = u8> {
|
|
LL + fn f() -> impl DerefMut<Target = u8> {
|
|
|
|
|
|
|
error: this bound is already specified as the supertrait of `DerefMut<Target = u8>`
|
|
--> $DIR/implied_bounds_in_impls.rs:63:20
|
|
|
|
|
LL | fn f() -> impl Deref + DerefMut<Target = u8> {
|
|
| ^^^^^
|
|
|
|
|
help: try removing this bound
|
|
|
|
|
LL - fn f() -> impl Deref + DerefMut<Target = u8> {
|
|
LL + fn f() -> impl DerefMut<Target = u8> {
|
|
|
|
|
|
|
error: this bound is already specified as the supertrait of `PartialOrd`
|
|
--> $DIR/implied_bounds_in_impls.rs:74:41
|
|
|
|
|
LL | fn default_generic_param1() -> impl PartialEq + PartialOrd + Debug {}
|
|
| ^^^^^^^^^
|
|
|
|
|
help: try removing this bound
|
|
|
|
|
LL - fn default_generic_param1() -> impl PartialEq + PartialOrd + Debug {}
|
|
LL + fn default_generic_param1() -> impl PartialOrd + Debug {}
|
|
|
|
|
|
|
error: this bound is already specified as the supertrait of `PartialOrd`
|
|
--> $DIR/implied_bounds_in_impls.rs:75:54
|
|
|
|
|
LL | fn default_generic_param2() -> impl PartialOrd + PartialEq + Debug {}
|
|
| ^^^^^^^^^
|
|
|
|
|
help: try removing this bound
|
|
|
|
|
LL - fn default_generic_param2() -> impl PartialOrd + PartialEq + Debug {}
|
|
LL + fn default_generic_param2() -> impl PartialOrd + Debug {}
|
|
|
|
|
|
|
error: this bound is already specified as the supertrait of `DoubleEndedIterator`
|
|
--> $DIR/implied_bounds_in_impls.rs:88:26
|
|
|
|
|
LL | fn my_iter() -> impl Iterator<Item = u32> + DoubleEndedIterator {
|
|
| ^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: try removing this bound
|
|
|
|
|
LL - fn my_iter() -> impl Iterator<Item = u32> + DoubleEndedIterator {
|
|
LL + fn my_iter() -> impl DoubleEndedIterator<Item = u32> {
|
|
|
|
|
|
|
error: this bound is already specified as the supertrait of `Copy`
|
|
--> $DIR/implied_bounds_in_impls.rs:93:27
|
|
|
|
|
LL | fn f() -> impl Copy + Clone {
|
|
| ^^^^^
|
|
|
|
|
help: try removing this bound
|
|
|
|
|
LL - fn f() -> impl Copy + Clone {
|
|
LL + fn f() -> impl Copy {
|
|
|
|
|
|
|
error: this bound is already specified as the supertrait of `Trait2<i32>`
|
|
--> $DIR/implied_bounds_in_impls.rs:107:21
|
|
|
|
|
LL | fn f2() -> impl Trait1<i32, U = i64> + Trait2<i32> {}
|
|
| ^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: try removing this bound
|
|
|
|
|
LL - fn f2() -> impl Trait1<i32, U = i64> + Trait2<i32> {}
|
|
LL + fn f2() -> impl Trait2<i32, U = i64> {}
|
|
|
|
|
|
|
error: this bound is already specified as the supertrait of `Trait4<i8, X = i32>`
|
|
--> $DIR/implied_bounds_in_impls.rs:122:21
|
|
|
|
|
LL | fn f3() -> impl Trait3<i8, i16, i64, X = i32, Y = i128> + Trait4<i8, X = i32> {}
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: try removing this bound
|
|
|
|
|
LL - fn f3() -> impl Trait3<i8, i16, i64, X = i32, Y = i128> + Trait4<i8, X = i32> {}
|
|
LL + fn f3() -> impl Trait4<i8, X = i32, Y = i128> {}
|
|
|
|
|
|
|
error: aborting due to 16 previous errors
|
|
|