Skip to content

Commit 936d760

Browse files
authored
Rollup merge of #126127 - Alexendoo:other-trait-diag, r=pnkfelix
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
2 parents e4bc7de + d0112c6 commit 936d760

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+348
-348
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2068,7 +2068,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
20682068
if all_traits_equal {
20692069
format!("\n {}", c.self_ty())
20702070
} else {
2071-
format!("\n {c}")
2071+
format!("\n `{}` implements `{}`", c.self_ty(), c.print_only_trait_path())
20722072
}
20732073
})
20742074
.collect();

tests/ui/binop/binary-op-suggest-deref.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,10 @@ LL | let _ = FOO & (*"Sized".to_string().into_boxed_str());
303303
|
304304
= help: the trait `BitAnd<str>` is not implemented for `i32`
305305
= help: the following other types implement trait `BitAnd<Rhs>`:
306-
<&'a i32 as BitAnd<i32>>
307-
<&i32 as BitAnd<&i32>>
308-
<i32 as BitAnd<&i32>>
309-
<i32 as BitAnd>
306+
`&'a i32` implements `BitAnd<i32>`
307+
`&i32` implements `BitAnd<&i32>`
308+
`i32` implements `BitAnd<&i32>`
309+
`i32` implements `BitAnd`
310310

311311
error[E0277]: the size for values of type `str` cannot be known at compilation time
312312
--> $DIR/binary-op-suggest-deref.rs:78:17

tests/ui/binop/binop-mul-i32-f32.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ LL | x * y
66
|
77
= help: the trait `Mul<f32>` is not implemented for `i32`
88
= help: the following other types implement trait `Mul<Rhs>`:
9-
<&'a i32 as Mul<i32>>
10-
<&i32 as Mul<&i32>>
11-
<i32 as Mul<&i32>>
12-
<i32 as Mul>
9+
`&'a i32` implements `Mul<i32>`
10+
`&i32` implements `Mul<&i32>`
11+
`i32` implements `Mul<&i32>`
12+
`i32` implements `Mul`
1313

1414
error: aborting due to 1 previous error
1515

tests/ui/binop/shift-various-bad-types.stderr

+24-24
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ LL | 22 >> p.char;
66
|
77
= help: the trait `Shr<char>` is not implemented for `{integer}`
88
= help: the following other types implement trait `Shr<Rhs>`:
9-
<&'a i128 as Shr<i128>>
10-
<&'a i128 as Shr<i16>>
11-
<&'a i128 as Shr<i32>>
12-
<&'a i128 as Shr<i64>>
13-
<&'a i128 as Shr<i8>>
14-
<&'a i128 as Shr<isize>>
15-
<&'a i128 as Shr<u128>>
16-
<&'a i128 as Shr<u16>>
9+
`&'a i128` implements `Shr<i128>`
10+
`&'a i128` implements `Shr<i16>`
11+
`&'a i128` implements `Shr<i32>`
12+
`&'a i128` implements `Shr<i64>`
13+
`&'a i128` implements `Shr<i8>`
14+
`&'a i128` implements `Shr<isize>`
15+
`&'a i128` implements `Shr<u128>`
16+
`&'a i128` implements `Shr<u16>`
1717
and 568 others
1818

1919
error[E0277]: no implementation for `{integer} >> &str`
@@ -24,14 +24,14 @@ LL | 22 >> p.str;
2424
|
2525
= help: the trait `Shr<&str>` is not implemented for `{integer}`
2626
= help: the following other types implement trait `Shr<Rhs>`:
27-
<&'a i128 as Shr<i128>>
28-
<&'a i128 as Shr<i16>>
29-
<&'a i128 as Shr<i32>>
30-
<&'a i128 as Shr<i64>>
31-
<&'a i128 as Shr<i8>>
32-
<&'a i128 as Shr<isize>>
33-
<&'a i128 as Shr<u128>>
34-
<&'a i128 as Shr<u16>>
27+
`&'a i128` implements `Shr<i128>`
28+
`&'a i128` implements `Shr<i16>`
29+
`&'a i128` implements `Shr<i32>`
30+
`&'a i128` implements `Shr<i64>`
31+
`&'a i128` implements `Shr<i8>`
32+
`&'a i128` implements `Shr<isize>`
33+
`&'a i128` implements `Shr<u128>`
34+
`&'a i128` implements `Shr<u16>`
3535
and 568 others
3636

3737
error[E0277]: no implementation for `{integer} >> &Panolpy`
@@ -42,14 +42,14 @@ LL | 22 >> p;
4242
|
4343
= help: the trait `Shr<&Panolpy>` is not implemented for `{integer}`
4444
= help: the following other types implement trait `Shr<Rhs>`:
45-
<&'a i128 as Shr<i128>>
46-
<&'a i128 as Shr<i16>>
47-
<&'a i128 as Shr<i32>>
48-
<&'a i128 as Shr<i64>>
49-
<&'a i128 as Shr<i8>>
50-
<&'a i128 as Shr<isize>>
51-
<&'a i128 as Shr<u128>>
52-
<&'a i128 as Shr<u16>>
45+
`&'a i128` implements `Shr<i128>`
46+
`&'a i128` implements `Shr<i16>`
47+
`&'a i128` implements `Shr<i32>`
48+
`&'a i128` implements `Shr<i64>`
49+
`&'a i128` implements `Shr<i8>`
50+
`&'a i128` implements `Shr<isize>`
51+
`&'a i128` implements `Shr<u128>`
52+
`&'a i128` implements `Shr<u16>`
5353
and 568 others
5454

5555
error[E0308]: mismatched types

tests/ui/const-generics/exhaustive-value.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ LL | <() as Foo<N>>::test()
55
| ^^ the trait `Foo<N>` is not implemented for `()`
66
|
77
= help: the following other types implement trait `Foo<N>`:
8-
<() as Foo<0>>
9-
<() as Foo<100>>
10-
<() as Foo<101>>
11-
<() as Foo<102>>
12-
<() as Foo<103>>
13-
<() as Foo<104>>
14-
<() as Foo<105>>
15-
<() as Foo<106>>
8+
`()` implements `Foo<0>`
9+
`()` implements `Foo<100>`
10+
`()` implements `Foo<101>`
11+
`()` implements `Foo<102>`
12+
`()` implements `Foo<103>`
13+
`()` implements `Foo<104>`
14+
`()` implements `Foo<105>`
15+
`()` implements `Foo<106>`
1616
and 248 others
1717

1818
error: aborting due to 1 previous error

tests/ui/consts/const-eval/const-eval-overflow-3b.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ LL | = [0; (i8::MAX + 1u8) as usize];
1212
|
1313
= help: the trait `Add<u8>` is not implemented for `i8`
1414
= help: the following other types implement trait `Add<Rhs>`:
15-
<&'a i8 as Add<i8>>
16-
<&i8 as Add<&i8>>
17-
<i8 as Add<&i8>>
18-
<i8 as Add>
15+
`&'a i8` implements `Add<i8>`
16+
`&i8` implements `Add<&i8>`
17+
`i8` implements `Add<&i8>`
18+
`i8` implements `Add`
1919

2020
error: aborting due to 2 previous errors
2121

tests/ui/consts/const-eval/const-eval-overflow-4b.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ LL | : [u32; (i8::MAX as i8 + 1u8) as usize]
1212
|
1313
= help: the trait `Add<u8>` is not implemented for `i8`
1414
= help: the following other types implement trait `Add<Rhs>`:
15-
<&'a i8 as Add<i8>>
16-
<&i8 as Add<&i8>>
17-
<i8 as Add<&i8>>
18-
<i8 as Add>
15+
`&'a i8` implements `Add<i8>`
16+
`&i8` implements `Add<&i8>`
17+
`i8` implements `Add<&i8>`
18+
`i8` implements `Add`
1919

2020
error[E0604]: only `u8` can be cast as `char`, not `i8`
2121
--> $DIR/const-eval-overflow-4b.rs:22:13

tests/ui/consts/too_generic_eval_ice.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ LL | [5; Self::HOST_SIZE] == [6; 0]
2222
|
2323
= help: the trait `PartialEq<[{integer}; 0]>` is not implemented for `[{integer}; Self::HOST_SIZE]`
2424
= help: the following other types implement trait `PartialEq<Rhs>`:
25-
<&[T] as PartialEq<Vec<U, A>>>
26-
<&[T] as PartialEq<[U; N]>>
27-
<&mut [T] as PartialEq<Vec<U, A>>>
28-
<&mut [T] as PartialEq<[U; N]>>
29-
<[T; N] as PartialEq<&[U]>>
30-
<[T; N] as PartialEq<&mut [U]>>
31-
<[T; N] as PartialEq<[U; N]>>
32-
<[T; N] as PartialEq<[U]>>
25+
`&[T]` implements `PartialEq<Vec<U, A>>`
26+
`&[T]` implements `PartialEq<[U; N]>`
27+
`&mut [T]` implements `PartialEq<Vec<U, A>>`
28+
`&mut [T]` implements `PartialEq<[U; N]>`
29+
`[T; N]` implements `PartialEq<&[U]>`
30+
`[T; N]` implements `PartialEq<&mut [U]>`
31+
`[T; N]` implements `PartialEq<[U; N]>`
32+
`[T; N]` implements `PartialEq<[U]>`
3333
and 3 others
3434

3535
error: aborting due to 3 previous errors

tests/ui/did_you_mean/issue-21659-show-relevant-trait-impls-1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | f1.foo(1usize);
77
| required by a bound introduced by this call
88
|
99
= help: the following other types implement trait `Foo<A>`:
10-
<Bar as Foo<i32>>
11-
<Bar as Foo<u8>>
10+
`Bar` implements `Foo<i32>`
11+
`Bar` implements `Foo<u8>`
1212

1313
error: aborting due to 1 previous error
1414

tests/ui/did_you_mean/issue-21659-show-relevant-trait-impls-2.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ LL | f1.foo(1usize);
77
| required by a bound introduced by this call
88
|
99
= help: the following other types implement trait `Foo<A>`:
10-
<Bar as Foo<i16>>
11-
<Bar as Foo<i32>>
12-
<Bar as Foo<i8>>
13-
<Bar as Foo<u16>>
14-
<Bar as Foo<u32>>
15-
<Bar as Foo<u8>>
10+
`Bar` implements `Foo<i16>`
11+
`Bar` implements `Foo<i32>`
12+
`Bar` implements `Foo<i8>`
13+
`Bar` implements `Foo<u16>`
14+
`Bar` implements `Foo<u32>`
15+
`Bar` implements `Foo<u8>`
1616

1717
error: aborting due to 1 previous error
1818

tests/ui/did_you_mean/issue-39802-show-5-trait-impls.stderr

+15-15
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ LL | Foo::<i32>::bar(&1i8);
77
| required by a bound introduced by this call
88
|
99
= help: the following other types implement trait `Foo<B>`:
10-
<i8 as Foo<bool>>
11-
<i8 as Foo<u16>>
12-
<i8 as Foo<u32>>
13-
<i8 as Foo<u64>>
14-
<i8 as Foo<u8>>
10+
`i8` implements `Foo<bool>`
11+
`i8` implements `Foo<u16>`
12+
`i8` implements `Foo<u32>`
13+
`i8` implements `Foo<u64>`
14+
`i8` implements `Foo<u8>`
1515

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

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

4646
error: aborting due to 3 previous errors
4747

tests/ui/impl-trait/equality.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ LL | n + sum_to(n - 1)
3030
|
3131
= help: the trait `Add<impl Foo>` is not implemented for `u32`
3232
= help: the following other types implement trait `Add<Rhs>`:
33-
<&'a u32 as Add<u32>>
34-
<&u32 as Add<&u32>>
35-
<u32 as Add<&u32>>
36-
<u32 as Add>
33+
`&'a u32` implements `Add<u32>`
34+
`&u32` implements `Add<&u32>`
35+
`u32` implements `Add<&u32>`
36+
`u32` implements `Add`
3737

3838
error: aborting due to 2 previous errors; 1 warning emitted
3939

tests/ui/issues/issue-11771.stderr

+16-16
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ LL | 1 +
66
|
77
= help: the trait `Add<()>` is not implemented for `{integer}`
88
= help: the following other types implement trait `Add<Rhs>`:
9-
<&'a f128 as Add<f128>>
10-
<&'a f16 as Add<f16>>
11-
<&'a f32 as Add<f32>>
12-
<&'a f64 as Add<f64>>
13-
<&'a i128 as Add<i128>>
14-
<&'a i16 as Add<i16>>
15-
<&'a i32 as Add<i32>>
16-
<&'a i64 as Add<i64>>
9+
`&'a f128` implements `Add<f128>`
10+
`&'a f16` implements `Add<f16>`
11+
`&'a f32` implements `Add<f32>`
12+
`&'a f64` implements `Add<f64>`
13+
`&'a i128` implements `Add<i128>`
14+
`&'a i16` implements `Add<i16>`
15+
`&'a i32` implements `Add<i32>`
16+
`&'a i64` implements `Add<i64>`
1717
and 56 others
1818

1919
error[E0277]: cannot add `()` to `{integer}`
@@ -24,14 +24,14 @@ LL | 1 +
2424
|
2525
= help: the trait `Add<()>` is not implemented for `{integer}`
2626
= help: the following other types implement trait `Add<Rhs>`:
27-
<&'a f128 as Add<f128>>
28-
<&'a f16 as Add<f16>>
29-
<&'a f32 as Add<f32>>
30-
<&'a f64 as Add<f64>>
31-
<&'a i128 as Add<i128>>
32-
<&'a i16 as Add<i16>>
33-
<&'a i32 as Add<i32>>
34-
<&'a i64 as Add<i64>>
27+
`&'a f128` implements `Add<f128>`
28+
`&'a f16` implements `Add<f16>`
29+
`&'a f32` implements `Add<f32>`
30+
`&'a f64` implements `Add<f64>`
31+
`&'a i128` implements `Add<i128>`
32+
`&'a i16` implements `Add<i16>`
33+
`&'a i32` implements `Add<i32>`
34+
`&'a i64` implements `Add<i64>`
3535
and 56 others
3636

3737
error: aborting due to 2 previous errors

tests/ui/issues/issue-24352.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ LL | 1.0f64 - 1
66
|
77
= help: the trait `Sub<{integer}>` is not implemented for `f64`
88
= help: the following other types implement trait `Sub<Rhs>`:
9-
<&'a f64 as Sub<f64>>
10-
<&f64 as Sub<&f64>>
11-
<f64 as Sub<&f64>>
12-
<f64 as Sub>
9+
`&'a f64` implements `Sub<f64>`
10+
`&f64` implements `Sub<&f64>`
11+
`f64` implements `Sub<&f64>`
12+
`f64` implements `Sub`
1313
help: consider using a floating-point literal by writing it with `.0`
1414
|
1515
LL | 1.0f64 - 1.0

tests/ui/issues/issue-50582.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ LL | Vec::<[(); 1 + for x in 0..1 {}]>::new();
1616
|
1717
= help: the trait `Add<()>` is not implemented for `{integer}`
1818
= help: the following other types implement trait `Add<Rhs>`:
19-
<&'a f128 as Add<f128>>
20-
<&'a f16 as Add<f16>>
21-
<&'a f32 as Add<f32>>
22-
<&'a f64 as Add<f64>>
23-
<&'a i128 as Add<i128>>
24-
<&'a i16 as Add<i16>>
25-
<&'a i32 as Add<i32>>
26-
<&'a i64 as Add<i64>>
19+
`&'a f128` implements `Add<f128>`
20+
`&'a f16` implements `Add<f16>`
21+
`&'a f32` implements `Add<f32>`
22+
`&'a f64` implements `Add<f64>`
23+
`&'a i128` implements `Add<i128>`
24+
`&'a i16` implements `Add<i16>`
25+
`&'a i32` implements `Add<i32>`
26+
`&'a i64` implements `Add<i64>`
2727
and 56 others
2828

2929
error: aborting due to 2 previous errors

tests/ui/iterators/invalid-iterator-chain-fixable.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ LL | println!("{}", scores.sum::<i32>());
3333
|
3434
= help: the trait `Sum<()>` is not implemented for `i32`
3535
= help: the following other types implement trait `Sum<A>`:
36-
<i32 as Sum<&'a i32>>
37-
<i32 as Sum>
36+
`i32` implements `Sum<&'a i32>`
37+
`i32` implements `Sum`
3838
note: the method call chain might not have had the expected associated types
3939
--> $DIR/invalid-iterator-chain-fixable.rs:14:10
4040
|
@@ -66,8 +66,8 @@ LL | .sum::<i32>(),
6666
|
6767
= help: the trait `Sum<()>` is not implemented for `i32`
6868
= help: the following other types implement trait `Sum<A>`:
69-
<i32 as Sum<&'a i32>>
70-
<i32 as Sum>
69+
`i32` implements `Sum<&'a i32>`
70+
`i32` implements `Sum`
7171
note: the method call chain might not have had the expected associated types
7272
--> $DIR/invalid-iterator-chain-fixable.rs:23:14
7373
|
@@ -99,8 +99,8 @@ LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>());
9999
|
100100
= help: the trait `Sum<()>` is not implemented for `i32`
101101
= help: the following other types implement trait `Sum<A>`:
102-
<i32 as Sum<&'a i32>>
103-
<i32 as Sum>
102+
`i32` implements `Sum<&'a i32>`
103+
`i32` implements `Sum`
104104
note: the method call chain might not have had the expected associated types
105105
--> $DIR/invalid-iterator-chain-fixable.rs:27:38
106106
|

0 commit comments

Comments
 (0)