Skip to content

Commit 1302d1f

Browse files
committed
Sort reported 'similar impl candidates' alphabetically
Fixes rust-lang#53302
1 parent fa23350 commit 1302d1f

5 files changed

+37
-4
lines changed

Diff for: src/librustc/traits/error_reporting.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
442442
return;
443443
}
444444

445-
let len = impl_candidates.len();
445+
impl_candidates.sort_by_cached_key(ToString::to_string);
446+
446447
let end = if impl_candidates.len() <= 5 {
447448
impl_candidates.len()
448449
} else {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | f1.foo(1usize);
88
<Bar as Foo<i16>>
99
<Bar as Foo<i32>>
1010
<Bar as Foo<i8>>
11-
<Bar as Foo<u8>>
11+
<Bar as Foo<u16>>
1212
and 2 others
1313

1414
error: aborting due to previous error

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -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<bool>>
44+
<bool as Foo<i8>>
4345
<bool as Foo<u16>>
4446
<bool as Foo<u32>>
45-
<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

Diff for: src/test/ui/report-similar-candidates-ordering.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// issue-53302
12+
13+
fn main() {
14+
let _: i32 = "".into(); //~ ERROR [E0277]
15+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: the trait bound `i32: std::convert::From<&str>` is not satisfied
2+
--> $DIR/report-similar-candidates-ordering.rs:14:21
3+
|
4+
LL | let _: i32 = "".into(); //~ ERROR [E0277]
5+
| ^^^^ the trait `std::convert::From<&str>` is not implemented for `i32`
6+
|
7+
= help: the following implementations were found:
8+
<i32 as std::convert::From<bool>>
9+
<i32 as std::convert::From<i16>>
10+
<i32 as std::convert::From<i8>>
11+
<i32 as std::convert::From<u16>>
12+
<i32 as std::convert::From<u8>>
13+
= note: required because of the requirements on the impl of `std::convert::Into<i32>` for `&str`
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)