diff options
| author | David Wood <david@davidtw.co> | 2018-08-09 14:37:27 +0200 |
|---|---|---|
| committer | David Wood <david@davidtw.co> | 2018-08-14 11:12:10 +0200 |
| commit | 8e7b9b81173ebf7a3d2a638b6ae477dd71a19217 (patch) | |
| tree | a52dab4e350d26e3f865b4696e4027af48998735 | |
| parent | dc5a6571a685189039feb9512dbcb599c1ef4102 (diff) | |
| download | rust-8e7b9b81173ebf7a3d2a638b6ae477dd71a19217.tar.gz rust-8e7b9b81173ebf7a3d2a638b6ae477dd71a19217.zip | |
Suggested trait implementation ordering is now deterministic.
4 files changed, 18 insertions, 10 deletions
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index a02b63755dc..7349c520c24 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -435,13 +435,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } fn report_similar_impl_candidates(&self, - impl_candidates: Vec<ty::TraitRef<'tcx>>, + mut impl_candidates: Vec<ty::TraitRef<'tcx>>, err: &mut DiagnosticBuilder) { if impl_candidates.is_empty() { return; } + let len = impl_candidates.len(); let end = if impl_candidates.len() <= 5 { impl_candidates.len() } else { @@ -459,10 +460,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } }); + // Sort impl candidates so that ordering is consistent for UI tests. + let normalized_impl_candidates = &mut impl_candidates[0..end] + .iter() + .map(normalize) + .collect::<Vec<String>>(); + normalized_impl_candidates.sort(); + err.help(&format!("the following implementations were found:{}{}", - &impl_candidates[0..end].iter().map(normalize).collect::<String>(), - if impl_candidates.len() > 5 { - format!("\nand {} others", impl_candidates.len() - 4) + normalized_impl_candidates.join(""), + if len > 5 { + format!("\nand {} others", len - 4) } else { "".to_owned() } diff --git a/src/test/ui/catch/catch-bad-type.stderr b/src/test/ui/catch/catch-bad-type.stderr index f7405e5e5c8..2ab5b3e3176 100644 --- a/src/test/ui/catch/catch-bad-type.stderr +++ b/src/test/ui/catch/catch-bad-type.stderr @@ -5,10 +5,10 @@ LL | Err("")?; //~ ERROR the trait bound `i32: std::convert::From<&str>` | ^^^^^^^^ the trait `std::convert::From<&str>` is not implemented for `i32` | = help: the following implementations were found: - <i32 as std::convert::From<u16>> <i32 as std::convert::From<bool>> <i32 as std::convert::From<i16>> <i32 as std::convert::From<i8>> + <i32 as std::convert::From<u16>> <i32 as std::convert::From<u8>> = note: required by `std::convert::From::from` diff --git a/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-2.stderr b/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-2.stderr index eee7f32032b..33804553a29 100644 --- a/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-2.stderr +++ b/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-2.stderr @@ -5,9 +5,9 @@ LL | f1.foo(1usize); | ^^^ the trait `Foo<usize>` is not implemented for `Bar` | = help: the following implementations were found: - <Bar as Foo<i8>> <Bar as Foo<i16>> <Bar as Foo<i32>> + <Bar as Foo<i8>> <Bar as Foo<u8>> and 2 others diff --git a/src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.stderr b/src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.stderr index 3f955da86ba..3b08fcf0df1 100644 --- a/src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.stderr +++ b/src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.stderr @@ -5,11 +5,11 @@ LL | Foo::<i32>::bar(&1i8); //~ ERROR is not satisfied | ^^^^^^^^^^^^^^^ the trait `Foo<i32>` is not implemented for `i8` | = help: the following implementations were found: - <i8 as Foo<u8>> + <i8 as Foo<bool>> <i8 as Foo<u16>> <i8 as Foo<u32>> <i8 as Foo<u64>> - <i8 as Foo<bool>> + <i8 as Foo<u8>> note: required by `Foo::bar` --> $DIR/issue-39802-show-5-trait-impls.rs:12:5 | @@ -23,10 +23,10 @@ LL | Foo::<i32>::bar(&1u8); //~ ERROR is not satisfied | ^^^^^^^^^^^^^^^ the trait `Foo<i32>` is not implemented for `u8` | = help: the following implementations were found: + <u8 as Foo<bool>> <u8 as Foo<u16>> <u8 as Foo<u32>> <u8 as Foo<u64>> - <u8 as Foo<bool>> note: required by `Foo::bar` --> $DIR/issue-39802-show-5-trait-impls.rs:12:5 | @@ -40,10 +40,10 @@ LL | Foo::<i32>::bar(&true); //~ ERROR is not satisfied | ^^^^^^^^^^^^^^^ the trait `Foo<i32>` is not implemented for `bool` | = help: the following implementations were found: - <bool as Foo<u8>> <bool as Foo<u16>> <bool as Foo<u32>> <bool as Foo<u64>> + <bool as Foo<u8>> and 2 others note: required by `Foo::bar` --> $DIR/issue-39802-show-5-trait-impls.rs:12:5 |
