diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 7349c520c2407..634d3e7dad18b 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -442,7 +442,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { return; } - let len = impl_candidates.len(); + impl_candidates.sort_by_cached_key(ToString::to_string); + let end = if impl_candidates.len() <= 5 { impl_candidates.len() } else { 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 33804553a2981..ff5c65aa98709 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 @@ -8,7 +8,7 @@ LL | f1.foo(1usize); > > > - > + > and 2 others error: aborting due to previous error 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 3b08fcf0df106..bdec426908e14 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 @@ -40,10 +40,10 @@ LL | Foo::::bar(&true); //~ ERROR is not satisfied | ^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `bool` | = help: the following implementations were found: + > + > > > - > - > and 2 others note: required by `Foo::bar` --> $DIR/issue-39802-show-5-trait-impls.rs:12:5 diff --git a/src/test/ui/report-similar-candidates-ordering.rs b/src/test/ui/report-similar-candidates-ordering.rs new file mode 100644 index 0000000000000..10b1f12c902fc --- /dev/null +++ b/src/test/ui/report-similar-candidates-ordering.rs @@ -0,0 +1,15 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// issue-53302 + +fn main() { + let _: i32 = "".into(); //~ ERROR [E0277] +} diff --git a/src/test/ui/report-similar-candidates-ordering.stderr b/src/test/ui/report-similar-candidates-ordering.stderr new file mode 100644 index 0000000000000..1dff7bba470a1 --- /dev/null +++ b/src/test/ui/report-similar-candidates-ordering.stderr @@ -0,0 +1,17 @@ +error[E0277]: the trait bound `i32: std::convert::From<&str>` is not satisfied + --> $DIR/report-similar-candidates-ordering.rs:14:21 + | +LL | let _: i32 = "".into(); //~ ERROR [E0277] + | ^^^^ the trait `std::convert::From<&str>` is not implemented for `i32` + | + = help: the following implementations were found: + > + > + > + > + > + = note: required because of the requirements on the impl of `std::convert::Into` for `&str` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`.