Skip to content

Commit 2c33dfe

Browse files
Don't sort strings right after we just sorted by types
1 parent 28f3986 commit 2c33dfe

Some content is hidden

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

44 files changed

+274
-270
lines changed

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

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,10 +1926,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
19261926
other: bool,
19271927
) -> bool {
19281928
let other = if other { "other " } else { "" };
1929-
let report = |mut candidates: Vec<TraitRef<'tcx>>, err: &mut Diagnostic| {
1930-
candidates.sort();
1931-
candidates.dedup();
1932-
let len = candidates.len();
1929+
let report = |candidates: Vec<TraitRef<'tcx>>, err: &mut Diagnostic| {
19331930
if candidates.is_empty() {
19341931
return false;
19351932
}
@@ -1958,26 +1955,31 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
19581955
candidates.iter().map(|c| c.print_only_trait_path().to_string()).collect();
19591956
traits.sort();
19601957
traits.dedup();
1958+
// FIXME: this could use a better heuristic, like just checking
1959+
// that substs[1..] is the same.
1960+
let all_traits_equal = traits.len() == 1;
19611961

1962-
let mut candidates: Vec<String> = candidates
1962+
let candidates: Vec<String> = candidates
19631963
.into_iter()
19641964
.map(|c| {
1965-
if traits.len() == 1 {
1965+
if all_traits_equal {
19661966
format!("\n {}", c.self_ty())
19671967
} else {
19681968
format!("\n {}", c)
19691969
}
19701970
})
19711971
.collect();
19721972

1973-
candidates.sort();
1974-
candidates.dedup();
19751973
let end = if candidates.len() <= 9 { candidates.len() } else { 8 };
19761974
err.help(format!(
19771975
"the following {other}types implement trait `{}`:{}{}",
19781976
trait_ref.print_only_trait_path(),
19791977
candidates[..end].join(""),
1980-
if len > 9 { format!("\nand {} others", len - 8) } else { String::new() }
1978+
if candidates.len() > 9 {
1979+
format!("\nand {} others", candidates.len() - 8)
1980+
} else {
1981+
String::new()
1982+
}
19811983
));
19821984
true
19831985
};
@@ -1991,7 +1993,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
19911993
// Mentioning implementers of `Copy`, `Debug` and friends is not useful.
19921994
return false;
19931995
}
1994-
let impl_candidates: Vec<_> = self
1996+
let mut impl_candidates: Vec<_> = self
19951997
.tcx
19961998
.all_impls(def_id)
19971999
// Ignore automatically derived impls and `!Trait` impls.
@@ -2018,6 +2020,9 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
20182020
}
20192021
})
20202022
.collect();
2023+
2024+
impl_candidates.sort();
2025+
impl_candidates.dedup();
20212026
return report(impl_candidates, err);
20222027
}
20232028

@@ -2027,26 +2032,25 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
20272032
//
20282033
// Prefer more similar candidates first, then sort lexicographically
20292034
// by their normalized string representation.
2030-
let mut impl_candidates = impl_candidates.to_vec();
2035+
let mut impl_candidates: Vec<_> = impl_candidates
2036+
.iter()
2037+
.cloned()
2038+
.map(|mut cand| {
2039+
// Fold the consts so that they shows up as, e.g., `10`
2040+
// instead of `core::::array::{impl#30}::{constant#0}`.
2041+
cand.trait_ref = cand.trait_ref.fold_with(&mut BottomUpFolder {
2042+
tcx: self.tcx,
2043+
ty_op: |ty| ty,
2044+
lt_op: |lt| lt,
2045+
ct_op: |ct| ct.eval(self.tcx, ty::ParamEnv::empty()),
2046+
});
2047+
cand
2048+
})
2049+
.collect();
20312050
impl_candidates.sort_by_key(|cand| (cand.similarity, cand.trait_ref));
20322051
impl_candidates.dedup();
20332052

2034-
report(
2035-
impl_candidates
2036-
.into_iter()
2037-
.map(|cand| {
2038-
// Fold the const so that it shows up as, e.g., `10`
2039-
// instead of `core::::array::{impl#30}::{constant#0}`.
2040-
cand.trait_ref.fold_with(&mut BottomUpFolder {
2041-
tcx: self.tcx,
2042-
ty_op: |ty| ty,
2043-
lt_op: |lt| lt,
2044-
ct_op: |ct| ct.eval(self.tcx, ty::ParamEnv::empty()),
2045-
})
2046-
})
2047-
.collect(),
2048-
err,
2049-
)
2053+
report(impl_candidates.into_iter().map(|cand| cand.trait_ref).collect(), err)
20502054
}
20512055

20522056
fn report_similar_impl_candidates_for_root_obligation(

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

Lines changed: 2 additions & 2 deletions
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+
<i32 as Mul>
10+
<i32 as Mul<&i32>>
911
<&'a i32 as Mul<i32>>
1012
<&i32 as Mul<&i32>>
11-
<i32 as Mul<&i32>>
12-
<i32 as Mul>
1313

1414
error: aborting due to previous error
1515

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

Lines changed: 24 additions & 24 deletions
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+
<isize as Shr>
10+
<isize as Shr<i8>>
11+
<isize as Shr<i16>>
12+
<isize as Shr<i32>>
13+
<isize as Shr<i64>>
14+
<isize as Shr<i128>>
15+
<isize as Shr<usize>>
16+
<isize as Shr<u8>>
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+
<isize as Shr>
28+
<isize as Shr<i8>>
29+
<isize as Shr<i16>>
30+
<isize as Shr<i32>>
31+
<isize as Shr<i64>>
32+
<isize as Shr<i128>>
33+
<isize as Shr<usize>>
34+
<isize as Shr<u8>>
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+
<isize as Shr>
46+
<isize as Shr<i8>>
47+
<isize as Shr<i16>>
48+
<isize as Shr<i32>>
49+
<isize as Shr<i64>>
50+
<isize as Shr<i128>>
51+
<isize as Shr<usize>>
52+
<isize as Shr<u8>>
5353
and 568 others
5454

5555
error[E0308]: mismatched types

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ LL | <() as Foo<N>>::test()
66
|
77
= help: the following other types implement trait `Foo<N>`:
88
<() 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>>
9+
<() as Foo<1>>
10+
<() as Foo<2>>
11+
<() as Foo<3>>
12+
<() as Foo<4>>
13+
<() as Foo<5>>
14+
<() as Foo<6>>
15+
<() as Foo<7>>
1616
and 248 others
1717

1818
error: aborting due to previous error

tests/ui/const-generics/generic_arg_infer/issue-91614.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ LL | let y = Mask::<_, _>::splat(false);
66
|
77
= note: cannot satisfy `_: MaskElement`
88
= help: the following types implement trait `MaskElement`:
9+
isize
10+
i8
911
i16
1012
i32
1113
i64
12-
i8
13-
isize
1414
note: required by a bound in `Mask::<T, LANES>::splat`
1515
--> $SRC_DIR/core/src/../../portable-simd/crates/core_simd/src/masks.rs:LL:COL
1616
help: consider giving `y` an explicit type, where the type for type parameter `T` is specified

tests/ui/const-generics/issues/issue-67185-2.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ LL | <u8 as Baz>::Quaks: Bar,
55
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `[u16; 3]`
66
|
77
= help: the following other types implement trait `Bar`:
8-
[[u16; 3]; 3]
98
[u16; 4]
9+
[[u16; 3]; 3]
1010
= help: see issue #48214
1111
= help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
1212

@@ -17,8 +17,8 @@ LL | [<u8 as Baz>::Quaks; 2]: Bar,
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `[[u16; 3]; 2]`
1818
|
1919
= help: the following other types implement trait `Bar`:
20-
[[u16; 3]; 3]
2120
[u16; 4]
21+
[[u16; 3]; 3]
2222
= help: see issue #48214
2323
= help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
2424

@@ -29,8 +29,8 @@ LL | impl Foo for FooImpl {}
2929
| ^^^ the trait `Bar` is not implemented for `[u16; 3]`
3030
|
3131
= help: the following other types implement trait `Bar`:
32-
[[u16; 3]; 3]
3332
[u16; 4]
33+
[[u16; 3]; 3]
3434
note: required by a bound in `Foo`
3535
--> $DIR/issue-67185-2.rs:15:25
3636
|
@@ -47,8 +47,8 @@ LL | impl Foo for FooImpl {}
4747
| ^^^ the trait `Bar` is not implemented for `[[u16; 3]; 2]`
4848
|
4949
= help: the following other types implement trait `Bar`:
50-
[[u16; 3]; 3]
5150
[u16; 4]
51+
[[u16; 3]; 3]
5252
note: required by a bound in `Foo`
5353
--> $DIR/issue-67185-2.rs:14:30
5454
|
@@ -65,8 +65,8 @@ LL | fn f(_: impl Foo) {}
6565
| ^^^ the trait `Bar` is not implemented for `[[u16; 3]; 2]`
6666
|
6767
= help: the following other types implement trait `Bar`:
68-
[[u16; 3]; 3]
6968
[u16; 4]
69+
[[u16; 3]; 3]
7070
note: required by a bound in `Foo`
7171
--> $DIR/issue-67185-2.rs:14:30
7272
|
@@ -83,8 +83,8 @@ LL | fn f(_: impl Foo) {}
8383
| ^^^ the trait `Bar` is not implemented for `[u16; 3]`
8484
|
8585
= help: the following other types implement trait `Bar`:
86-
[[u16; 3]; 3]
8786
[u16; 4]
87+
[[u16; 3]; 3]
8888
note: required by a bound in `Foo`
8989
--> $DIR/issue-67185-2.rs:15:25
9090
|

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

Lines changed: 2 additions & 2 deletions
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+
<i8 as Add>
16+
<i8 as Add<&i8>>
1517
<&'a i8 as Add<i8>>
1618
<&i8 as Add<&i8>>
17-
<i8 as Add<&i8>>
18-
<i8 as Add>
1919

2020
error: aborting due to 2 previous errors
2121

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

Lines changed: 2 additions & 2 deletions
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+
<i8 as Add>
16+
<i8 as Add<&i8>>
1517
<&'a i8 as Add<i8>>
1618
<&i8 as Add<&i8>>
17-
<i8 as Add<&i8>>
18-
<i8 as 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/missing-larger-array-impl.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ LL | <[X; 35] as Default>::default();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `[X; 35]`
66
|
77
= help: the following other types implement trait `Default`:
8-
&[T]
9-
&mut [T]
108
[T; 0]
11-
[T; 10]
12-
[T; 11]
13-
[T; 12]
14-
[T; 13]
15-
[T; 14]
9+
[T; 1]
10+
[T; 2]
11+
[T; 3]
12+
[T; 4]
13+
[T; 5]
14+
[T; 6]
15+
[T; 7]
1616
and 27 others
1717

1818
error: aborting due to previous error

tests/ui/consts/too_generic_eval_ice.stderr

Lines changed: 6 additions & 6 deletions
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-
<&[B] as PartialEq<[A; N]>>
26-
<&[T] as PartialEq<Vec<U, A>>>
27-
<&mut [B] as PartialEq<[A; N]>>
28-
<&mut [T] as PartialEq<Vec<U, A>>>
29-
<[A; N] as PartialEq<&[B]>>
30-
<[A; N] as PartialEq<&mut [B]>>
3125
<[A; N] as PartialEq<[B; N]>>
3226
<[A; N] as PartialEq<[B]>>
27+
<[A; N] as PartialEq<&[B]>>
28+
<[A; N] as PartialEq<&mut [B]>>
29+
<[T] as PartialEq<Vec<U, A>>>
30+
<[A] as PartialEq<[B]>>
31+
<[B] as PartialEq<[A; N]>>
32+
<&[T] as PartialEq<Vec<U, A>>>
3333
and 3 others
3434

3535
error: aborting due to 3 previous errors

tests/ui/deriving/issue-103157.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ LL | Float(Option<f64>),
88
| ^^^^^^^^^^^ the trait `Eq` is not implemented for `f64`
99
|
1010
= help: the following other types implement trait `Eq`:
11-
i128
11+
isize
12+
i8
1213
i16
1314
i32
1415
i64
15-
i8
16-
isize
17-
u128
18-
u16
16+
i128
17+
usize
18+
u8
1919
and 4 others
2020
= note: required for `Option<f64>` to implement `Eq`
2121
note: required by a bound in `AssertParamIsEq`

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

Lines changed: 2 additions & 2 deletions
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<i8>>
1011
<Bar as Foo<i16>>
1112
<Bar as Foo<i32>>
12-
<Bar as Foo<i8>>
13+
<Bar as Foo<u8>>
1314
<Bar as Foo<u16>>
1415
<Bar as Foo<u32>>
15-
<Bar as Foo<u8>>
1616

1717
error: aborting due to previous error
1818

0 commit comments

Comments
 (0)