Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort reported 'similar impl candidates' alphabetically #53323

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LL | f1.foo(1usize);
<Bar as Foo<i16>>
<Bar as Foo<i32>>
<Bar as Foo<i8>>
<Bar as Foo<u8>>
<Bar as Foo<u16>>
and 2 others

error: aborting due to previous error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>>
<bool as Foo<i8>>
<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
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/report-similar-candidates-ordering.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// issue-53302

This comment was marked as resolved.


fn main() {
let _: i32 = "".into(); //~ ERROR [E0277]
}
17 changes: 17 additions & 0 deletions src/test/ui/report-similar-candidates-ordering.stderr
Original file line number Diff line number Diff line change
@@ -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:
<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 because of the requirements on the impl of `std::convert::Into<i32>` for `&str`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.