Skip to content

Commit 1d67b7b

Browse files
committed
Suggested trait implementation ordering is now deterministic.
1 parent 1c4f99a commit 1d67b7b

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

src/librustc/traits/error_reporting.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
435435
}
436436

437437
fn report_similar_impl_candidates(&self,
438-
impl_candidates: Vec<ty::TraitRef<'tcx>>,
438+
mut impl_candidates: Vec<ty::TraitRef<'tcx>>,
439439
err: &mut DiagnosticBuilder)
440440
{
441441
if impl_candidates.is_empty() {
442442
return;
443443
}
444444

445+
let len = impl_candidates.len();
445446
let end = if impl_candidates.len() <= 5 {
446447
impl_candidates.len()
447448
} else {
@@ -459,10 +460,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
459460
}
460461
});
461462

463+
// Sort impl candidates so that ordering is consistent for UI tests.
464+
let normalized_impl_candidates = &mut impl_candidates[0..end]
465+
.iter()
466+
.map(normalize)
467+
.collect::<Vec<String>>();
468+
normalized_impl_candidates.sort();
469+
462470
err.help(&format!("the following implementations were found:{}{}",
463-
&impl_candidates[0..end].iter().map(normalize).collect::<String>(),
464-
if impl_candidates.len() > 5 {
465-
format!("\nand {} others", impl_candidates.len() - 4)
471+
normalized_impl_candidates.join(""),
472+
if len > 5 {
473+
format!("\nand {} others", len - 4)
466474
} else {
467475
"".to_owned()
468476
}

src/test/ui/catch/catch-bad-type.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | Err("")?; //~ ERROR the trait bound `i32: std::convert::From<&str>`
55
| ^^^^^^^^ the trait `std::convert::From<&str>` is not implemented for `i32`
66
|
77
= help: the following implementations were found:
8-
<i32 as std::convert::From<u16>>
98
<i32 as std::convert::From<bool>>
109
<i32 as std::convert::From<i16>>
1110
<i32 as std::convert::From<i8>>
11+
<i32 as std::convert::From<u16>>
1212
<i32 as std::convert::From<u8>>
1313
= note: required by `std::convert::From::from`
1414

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ LL | f1.foo(1usize);
55
| ^^^ the trait `Foo<usize>` is not implemented for `Bar`
66
|
77
= help: the following implementations were found:
8-
<Bar as Foo<i8>>
98
<Bar as Foo<i16>>
109
<Bar as Foo<i32>>
10+
<Bar as Foo<i8>>
1111
<Bar as Foo<u8>>
1212
and 2 others
1313

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ LL | Foo::<i32>::bar(&1i8); //~ ERROR is not satisfied
55
| ^^^^^^^^^^^^^^^ the trait `Foo<i32>` is not implemented for `i8`
66
|
77
= help: the following implementations were found:
8-
<i8 as Foo<u8>>
8+
<i8 as Foo<bool>>
99
<i8 as Foo<u16>>
1010
<i8 as Foo<u32>>
1111
<i8 as Foo<u64>>
12-
<i8 as Foo<bool>>
12+
<i8 as Foo<u8>>
1313
note: required by `Foo::bar`
1414
--> $DIR/issue-39802-show-5-trait-impls.rs:12:5
1515
|
@@ -23,10 +23,10 @@ LL | Foo::<i32>::bar(&1u8); //~ ERROR is not satisfied
2323
| ^^^^^^^^^^^^^^^ the trait `Foo<i32>` is not implemented for `u8`
2424
|
2525
= help: the following implementations were found:
26+
<u8 as Foo<bool>>
2627
<u8 as Foo<u16>>
2728
<u8 as Foo<u32>>
2829
<u8 as Foo<u64>>
29-
<u8 as Foo<bool>>
3030
note: required by `Foo::bar`
3131
--> $DIR/issue-39802-show-5-trait-impls.rs:12:5
3232
|
@@ -40,10 +40,10 @@ LL | Foo::<i32>::bar(&true); //~ ERROR is not satisfied
4040
| ^^^^^^^^^^^^^^^ the trait `Foo<i32>` is not implemented for `bool`
4141
|
4242
= help: the following implementations were found:
43-
<bool as Foo<u8>>
4443
<bool as Foo<u16>>
4544
<bool as Foo<u32>>
4645
<bool as Foo<u64>>
46+
<bool as Foo<u8>>
4747
and 2 others
4848
note: required by `Foo::bar`
4949
--> $DIR/issue-39802-show-5-trait-impls.rs:12:5

0 commit comments

Comments
 (0)