Skip to content
/ rust Public
forked from rust-lang/rust

Commit

Permalink
Rollup merge of rust-lang#126127 - Alexendoo:other-trait-diag, r=pnkf…
Browse files Browse the repository at this point in the history
…elix

Spell out other trait diagnostic

I recently saw somebody confused about the diagnostic thinking it was suggesting to add an `as` cast. This change is longer but I think it's clearer
  • Loading branch information
jhpratt authored Jun 12, 2024
2 parents c8c16ff + 79dd1ca commit 2ab4e49
Show file tree
Hide file tree
Showing 39 changed files with 340 additions and 340 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
if all_traits_equal {
format!("\n {}", c.self_ty())
} else {
format!("\n {c}")
format!("\n `{}` implements `{}`", c.self_ty(), c.print_only_trait_path())
}
})
.collect();
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/binop/binary-op-suggest-deref.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@ LL | let _ = FOO & (*"Sized".to_string().into_boxed_str());
|
= help: the trait `BitAnd<str>` is not implemented for `i32`
= help: the following other types implement trait `BitAnd<Rhs>`:
<&'a i32 as BitAnd<i32>>
<&i32 as BitAnd<&i32>>
<i32 as BitAnd<&i32>>
<i32 as BitAnd>
`&'a i32` implements `BitAnd<i32>`
`&i32` implements `BitAnd<&i32>`
`i32` implements `BitAnd<&i32>`
`i32` implements `BitAnd`

error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/binary-op-suggest-deref.rs:78:17
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/binop/binop-mul-i32-f32.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ LL | x * y
|
= help: the trait `Mul<f32>` is not implemented for `i32`
= help: the following other types implement trait `Mul<Rhs>`:
<&'a i32 as Mul<i32>>
<&i32 as Mul<&i32>>
<i32 as Mul<&i32>>
<i32 as Mul>
`&'a i32` implements `Mul<i32>`
`&i32` implements `Mul<&i32>`
`i32` implements `Mul<&i32>`
`i32` implements `Mul`

error: aborting due to 1 previous error

Expand Down
48 changes: 24 additions & 24 deletions tests/ui/binop/shift-various-bad-types.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ LL | 22 >> p.char;
|
= help: the trait `Shr<char>` is not implemented for `{integer}`
= help: the following other types implement trait `Shr<Rhs>`:
<&'a i128 as Shr<i128>>
<&'a i128 as Shr<i16>>
<&'a i128 as Shr<i32>>
<&'a i128 as Shr<i64>>
<&'a i128 as Shr<i8>>
<&'a i128 as Shr<isize>>
<&'a i128 as Shr<u128>>
<&'a i128 as Shr<u16>>
`&'a i128` implements `Shr<i128>`
`&'a i128` implements `Shr<i16>`
`&'a i128` implements `Shr<i32>`
`&'a i128` implements `Shr<i64>`
`&'a i128` implements `Shr<i8>`
`&'a i128` implements `Shr<isize>`
`&'a i128` implements `Shr<u128>`
`&'a i128` implements `Shr<u16>`
and 568 others

error[E0277]: no implementation for `{integer} >> &str`
Expand All @@ -24,14 +24,14 @@ LL | 22 >> p.str;
|
= help: the trait `Shr<&str>` is not implemented for `{integer}`
= help: the following other types implement trait `Shr<Rhs>`:
<&'a i128 as Shr<i128>>
<&'a i128 as Shr<i16>>
<&'a i128 as Shr<i32>>
<&'a i128 as Shr<i64>>
<&'a i128 as Shr<i8>>
<&'a i128 as Shr<isize>>
<&'a i128 as Shr<u128>>
<&'a i128 as Shr<u16>>
`&'a i128` implements `Shr<i128>`
`&'a i128` implements `Shr<i16>`
`&'a i128` implements `Shr<i32>`
`&'a i128` implements `Shr<i64>`
`&'a i128` implements `Shr<i8>`
`&'a i128` implements `Shr<isize>`
`&'a i128` implements `Shr<u128>`
`&'a i128` implements `Shr<u16>`
and 568 others

error[E0277]: no implementation for `{integer} >> &Panolpy`
Expand All @@ -42,14 +42,14 @@ LL | 22 >> p;
|
= help: the trait `Shr<&Panolpy>` is not implemented for `{integer}`
= help: the following other types implement trait `Shr<Rhs>`:
<&'a i128 as Shr<i128>>
<&'a i128 as Shr<i16>>
<&'a i128 as Shr<i32>>
<&'a i128 as Shr<i64>>
<&'a i128 as Shr<i8>>
<&'a i128 as Shr<isize>>
<&'a i128 as Shr<u128>>
<&'a i128 as Shr<u16>>
`&'a i128` implements `Shr<i128>`
`&'a i128` implements `Shr<i16>`
`&'a i128` implements `Shr<i32>`
`&'a i128` implements `Shr<i64>`
`&'a i128` implements `Shr<i8>`
`&'a i128` implements `Shr<isize>`
`&'a i128` implements `Shr<u128>`
`&'a i128` implements `Shr<u16>`
and 568 others

error[E0308]: mismatched types
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/const-generics/exhaustive-value.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ LL | <() as Foo<N>>::test()
| ^^ the trait `Foo<N>` is not implemented for `()`
|
= help: the following other types implement trait `Foo<N>`:
<() as Foo<0>>
<() as Foo<100>>
<() as Foo<101>>
<() as Foo<102>>
<() as Foo<103>>
<() as Foo<104>>
<() as Foo<105>>
<() as Foo<106>>
`()` implements `Foo<0>`
`()` implements `Foo<100>`
`()` implements `Foo<101>`
`()` implements `Foo<102>`
`()` implements `Foo<103>`
`()` implements `Foo<104>`
`()` implements `Foo<105>`
`()` implements `Foo<106>`
and 248 others

error: aborting due to 1 previous error
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/consts/const-eval/const-eval-overflow-3b.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ LL | = [0; (i8::MAX + 1u8) as usize];
|
= help: the trait `Add<u8>` is not implemented for `i8`
= help: the following other types implement trait `Add<Rhs>`:
<&'a i8 as Add<i8>>
<&i8 as Add<&i8>>
<i8 as Add<&i8>>
<i8 as Add>
`&'a i8` implements `Add<i8>`
`&i8` implements `Add<&i8>`
`i8` implements `Add<&i8>`
`i8` implements `Add`

error: aborting due to 2 previous errors

Expand Down
8 changes: 4 additions & 4 deletions tests/ui/consts/const-eval/const-eval-overflow-4b.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ LL | : [u32; (i8::MAX as i8 + 1u8) as usize]
|
= help: the trait `Add<u8>` is not implemented for `i8`
= help: the following other types implement trait `Add<Rhs>`:
<&'a i8 as Add<i8>>
<&i8 as Add<&i8>>
<i8 as Add<&i8>>
<i8 as Add>
`&'a i8` implements `Add<i8>`
`&i8` implements `Add<&i8>`
`i8` implements `Add<&i8>`
`i8` implements `Add`

error[E0604]: only `u8` can be cast as `char`, not `i8`
--> $DIR/const-eval-overflow-4b.rs:22:13
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/consts/too_generic_eval_ice.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ LL | [5; Self::HOST_SIZE] == [6; 0]
|
= help: the trait `PartialEq<[{integer}; 0]>` is not implemented for `[{integer}; Self::HOST_SIZE]`
= help: the following other types implement trait `PartialEq<Rhs>`:
<&[T] as PartialEq<Vec<U, A>>>
<&[T] as PartialEq<[U; N]>>
<&mut [T] as PartialEq<Vec<U, A>>>
<&mut [T] as PartialEq<[U; N]>>
<[T; N] as PartialEq<&[U]>>
<[T; N] as PartialEq<&mut [U]>>
<[T; N] as PartialEq<[U; N]>>
<[T; N] as PartialEq<[U]>>
`&[T]` implements `PartialEq<Vec<U, A>>`
`&[T]` implements `PartialEq<[U; N]>`
`&mut [T]` implements `PartialEq<Vec<U, A>>`
`&mut [T]` implements `PartialEq<[U; N]>`
`[T; N]` implements `PartialEq<&[U]>`
`[T; N]` implements `PartialEq<&mut [U]>`
`[T; N]` implements `PartialEq<[U; N]>`
`[T; N]` implements `PartialEq<[U]>`
and 3 others

error: aborting due to 3 previous errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ LL | f1.foo(1usize);
| required by a bound introduced by this call
|
= help: the following other types implement trait `Foo<A>`:
<Bar as Foo<i32>>
<Bar as Foo<u8>>
`Bar` implements `Foo<i32>`
`Bar` implements `Foo<u8>`

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ LL | f1.foo(1usize);
| required by a bound introduced by this call
|
= help: the following other types implement trait `Foo<A>`:
<Bar as Foo<i16>>
<Bar as Foo<i32>>
<Bar as Foo<i8>>
<Bar as Foo<u16>>
<Bar as Foo<u32>>
<Bar as Foo<u8>>
`Bar` implements `Foo<i16>`
`Bar` implements `Foo<i32>`
`Bar` implements `Foo<i8>`
`Bar` implements `Foo<u16>`
`Bar` implements `Foo<u32>`
`Bar` implements `Foo<u8>`

error: aborting due to 1 previous error

Expand Down
30 changes: 15 additions & 15 deletions tests/ui/did_you_mean/issue-39802-show-5-trait-impls.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ LL | Foo::<i32>::bar(&1i8);
| required by a bound introduced by this call
|
= help: the following other types implement trait `Foo<B>`:
<i8 as Foo<bool>>
<i8 as Foo<u16>>
<i8 as Foo<u32>>
<i8 as Foo<u64>>
<i8 as Foo<u8>>
`i8` implements `Foo<bool>`
`i8` implements `Foo<u16>`
`i8` implements `Foo<u32>`
`i8` implements `Foo<u64>`
`i8` implements `Foo<u8>`

error[E0277]: the trait bound `u8: Foo<i32>` is not satisfied
--> $DIR/issue-39802-show-5-trait-impls.rs:25:21
Expand All @@ -22,10 +22,10 @@ LL | Foo::<i32>::bar(&1u8);
| required by a bound introduced by this call
|
= help: the following other types implement trait `Foo<B>`:
<u8 as Foo<bool>>
<u8 as Foo<u16>>
<u8 as Foo<u32>>
<u8 as Foo<u64>>
`u8` implements `Foo<bool>`
`u8` implements `Foo<u16>`
`u8` implements `Foo<u32>`
`u8` implements `Foo<u64>`

error[E0277]: the trait bound `bool: Foo<i32>` is not satisfied
--> $DIR/issue-39802-show-5-trait-impls.rs:26:21
Expand All @@ -36,12 +36,12 @@ LL | Foo::<i32>::bar(&true);
| required by a bound introduced by this call
|
= help: the following other types implement trait `Foo<B>`:
<bool as Foo<bool>>
<bool as Foo<i8>>
<bool as Foo<u16>>
<bool as Foo<u32>>
<bool as Foo<u64>>
<bool as Foo<u8>>
`bool` implements `Foo<bool>`
`bool` implements `Foo<i8>`
`bool` implements `Foo<u16>`
`bool` implements `Foo<u32>`
`bool` implements `Foo<u64>`
`bool` implements `Foo<u8>`

error: aborting due to 3 previous errors

Expand Down
32 changes: 16 additions & 16 deletions tests/ui/issues/issue-11771.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ LL | 1 +
|
= help: the trait `Add<()>` is not implemented for `{integer}`
= help: the following other types implement trait `Add<Rhs>`:
<&'a f128 as Add<f128>>
<&'a f16 as Add<f16>>
<&'a f32 as Add<f32>>
<&'a f64 as Add<f64>>
<&'a i128 as Add<i128>>
<&'a i16 as Add<i16>>
<&'a i32 as Add<i32>>
<&'a i64 as Add<i64>>
`&'a f128` implements `Add<f128>`
`&'a f16` implements `Add<f16>`
`&'a f32` implements `Add<f32>`
`&'a f64` implements `Add<f64>`
`&'a i128` implements `Add<i128>`
`&'a i16` implements `Add<i16>`
`&'a i32` implements `Add<i32>`
`&'a i64` implements `Add<i64>`
and 56 others

error[E0277]: cannot add `()` to `{integer}`
Expand All @@ -24,14 +24,14 @@ LL | 1 +
|
= help: the trait `Add<()>` is not implemented for `{integer}`
= help: the following other types implement trait `Add<Rhs>`:
<&'a f128 as Add<f128>>
<&'a f16 as Add<f16>>
<&'a f32 as Add<f32>>
<&'a f64 as Add<f64>>
<&'a i128 as Add<i128>>
<&'a i16 as Add<i16>>
<&'a i32 as Add<i32>>
<&'a i64 as Add<i64>>
`&'a f128` implements `Add<f128>`
`&'a f16` implements `Add<f16>`
`&'a f32` implements `Add<f32>`
`&'a f64` implements `Add<f64>`
`&'a i128` implements `Add<i128>`
`&'a i16` implements `Add<i16>`
`&'a i32` implements `Add<i32>`
`&'a i64` implements `Add<i64>`
and 56 others

error: aborting due to 2 previous errors
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/issues/issue-24352.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ LL | 1.0f64 - 1
|
= help: the trait `Sub<{integer}>` is not implemented for `f64`
= help: the following other types implement trait `Sub<Rhs>`:
<&'a f64 as Sub<f64>>
<&f64 as Sub<&f64>>
<f64 as Sub<&f64>>
<f64 as Sub>
`&'a f64` implements `Sub<f64>`
`&f64` implements `Sub<&f64>`
`f64` implements `Sub<&f64>`
`f64` implements `Sub`
help: consider using a floating-point literal by writing it with `.0`
|
LL | 1.0f64 - 1.0
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/issues/issue-50582.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ LL | Vec::<[(); 1 + for x in 0..1 {}]>::new();
|
= help: the trait `Add<()>` is not implemented for `{integer}`
= help: the following other types implement trait `Add<Rhs>`:
<&'a f128 as Add<f128>>
<&'a f16 as Add<f16>>
<&'a f32 as Add<f32>>
<&'a f64 as Add<f64>>
<&'a i128 as Add<i128>>
<&'a i16 as Add<i16>>
<&'a i32 as Add<i32>>
<&'a i64 as Add<i64>>
`&'a f128` implements `Add<f128>`
`&'a f16` implements `Add<f16>`
`&'a f32` implements `Add<f32>`
`&'a f64` implements `Add<f64>`
`&'a i128` implements `Add<i128>`
`&'a i16` implements `Add<i16>`
`&'a i32` implements `Add<i32>`
`&'a i64` implements `Add<i64>`
and 56 others

error: aborting due to 2 previous errors
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/iterators/invalid-iterator-chain-fixable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ LL | println!("{}", scores.sum::<i32>());
|
= help: the trait `Sum<()>` is not implemented for `i32`
= help: the following other types implement trait `Sum<A>`:
<i32 as Sum<&'a i32>>
<i32 as Sum>
`i32` implements `Sum<&'a i32>`
`i32` implements `Sum`
note: the method call chain might not have had the expected associated types
--> $DIR/invalid-iterator-chain-fixable.rs:14:10
|
Expand Down Expand Up @@ -66,8 +66,8 @@ LL | .sum::<i32>(),
|
= help: the trait `Sum<()>` is not implemented for `i32`
= help: the following other types implement trait `Sum<A>`:
<i32 as Sum<&'a i32>>
<i32 as Sum>
`i32` implements `Sum<&'a i32>`
`i32` implements `Sum`
note: the method call chain might not have had the expected associated types
--> $DIR/invalid-iterator-chain-fixable.rs:23:14
|
Expand Down Expand Up @@ -99,8 +99,8 @@ LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>());
|
= help: the trait `Sum<()>` is not implemented for `i32`
= help: the following other types implement trait `Sum<A>`:
<i32 as Sum<&'a i32>>
<i32 as Sum>
`i32` implements `Sum<&'a i32>`
`i32` implements `Sum`
note: the method call chain might not have had the expected associated types
--> $DIR/invalid-iterator-chain-fixable.rs:27:38
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ LL | let x = Some(()).iter().map(|()| 1).sum::<f32>();
|
= help: the trait `Sum<{integer}>` is not implemented for `f32`
= help: the following other types implement trait `Sum<A>`:
<f32 as Sum<&'a f32>>
<f32 as Sum>
`f32` implements `Sum<&'a f32>`
`f32` implements `Sum`
note: the method call chain might not have had the expected associated types
--> $DIR/invalid-iterator-chain-with-int-infer.rs:2:29
|
Expand Down
Loading

0 comments on commit 2ab4e49

Please sign in to comment.