Skip to content

Commit a66599f

Browse files
committed
keep predicate order and tweak output
1 parent 529b891 commit a66599f

19 files changed

+129
-79
lines changed

src/librustc_typeck/check/method/suggest.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
644644
},
645645
})
646646
})
647-
.collect::<Vec<String>>();
647+
.enumerate()
648+
.collect::<Vec<(usize, String)>>();
648649
for ((span, empty_where), obligations) in type_params.into_iter() {
649650
err.span_suggestion_verbose(
650651
span,
@@ -662,15 +663,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
662663
);
663664
}
664665

665-
bound_list.sort();
666-
bound_list.dedup(); // #35677
666+
bound_list.sort_by(|(_, a), (_, b)| a.cmp(&b)); // Sort alphabetically.
667+
bound_list.dedup_by(|(_, a), (_, b)| a == b); // #35677
668+
bound_list.sort_by_key(|(pos, _)| *pos); // Keep the original predicate order.
667669
bound_spans.sort();
668670
bound_spans.dedup();
669671
for (span, msg) in bound_spans.into_iter() {
670672
err.span_label(span, &msg);
671673
}
672674
if !bound_list.is_empty() {
673-
let bound_list = bound_list.join("\n");
675+
let bound_list = bound_list
676+
.into_iter()
677+
.map(|(_, path)| path)
678+
.collect::<Vec<_>>()
679+
.join("\n");
674680
err.note(&format!(
675681
"the method `{}` exists but the following trait bounds were not \
676682
satisfied:\n{}",
@@ -1095,7 +1101,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10951101
let mut use_note = true;
10961102
if let [trait_info] = &candidates[..] {
10971103
if let Some(span) = self.tcx.hir().span_if_local(trait_info.def_id) {
1098-
err.span_label(
1104+
err.span_note(
10991105
self.tcx.sess.source_map().def_span(span),
11001106
&format!(
11011107
"`{}` defines an item `{}`, perhaps you need to {} it",

src/test/ui/associated-const/associated-const-no-item.stderr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
error[E0599]: no associated item named `ID` found for type `i32` in the current scope
22
--> $DIR/associated-const-no-item.rs:5:23
33
|
4-
LL | trait Foo {
5-
| --------- `Foo` defines an item `ID`, perhaps you need to implement it
6-
...
74
LL | const X: i32 = <i32>::ID;
85
| ^^ associated item not found in `i32`
96
|
107
= help: items from traits can only be used if the trait is implemented and in scope
8+
note: `Foo` defines an item `ID`, perhaps you need to implement it
9+
--> $DIR/associated-const-no-item.rs:1:1
10+
|
11+
LL | trait Foo {
12+
| ^^^^^^^^^
1113

1214
error: aborting due to previous error
1315

src/test/ui/auto-ref-slice-plus-ref.stderr

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,52 @@ error[E0599]: no method named `test_mut` found for struct `std::vec::Vec<{intege
33
|
44
LL | a.test_mut();
55
| ^^^^^^^^ help: there is a method with a similar name: `get_mut`
6-
...
7-
LL | trait MyIter {
8-
| ------------ `MyIter` defines an item `test_mut`, perhaps you need to implement it
96
|
107
= help: items from traits can only be used if the trait is implemented and in scope
8+
note: `MyIter` defines an item `test_mut`, perhaps you need to implement it
9+
--> $DIR/auto-ref-slice-plus-ref.rs:14:1
10+
|
11+
LL | trait MyIter {
12+
| ^^^^^^^^^^^^
1113

1214
error[E0599]: no method named `test` found for struct `std::vec::Vec<{integer}>` in the current scope
1315
--> $DIR/auto-ref-slice-plus-ref.rs:8:7
1416
|
1517
LL | a.test();
1618
| ^^^^ method not found in `std::vec::Vec<{integer}>`
17-
...
18-
LL | trait MyIter {
19-
| ------------ `MyIter` defines an item `test`, perhaps you need to implement it
2019
|
2120
= help: items from traits can only be used if the trait is implemented and in scope
21+
note: `MyIter` defines an item `test`, perhaps you need to implement it
22+
--> $DIR/auto-ref-slice-plus-ref.rs:14:1
23+
|
24+
LL | trait MyIter {
25+
| ^^^^^^^^^^^^
2226

2327
error[E0599]: no method named `test` found for array `[{integer}; 1]` in the current scope
2428
--> $DIR/auto-ref-slice-plus-ref.rs:10:11
2529
|
2630
LL | ([1]).test();
2731
| ^^^^ method not found in `[{integer}; 1]`
28-
...
29-
LL | trait MyIter {
30-
| ------------ `MyIter` defines an item `test`, perhaps you need to implement it
3132
|
3233
= help: items from traits can only be used if the trait is implemented and in scope
34+
note: `MyIter` defines an item `test`, perhaps you need to implement it
35+
--> $DIR/auto-ref-slice-plus-ref.rs:14:1
36+
|
37+
LL | trait MyIter {
38+
| ^^^^^^^^^^^^
3339

3440
error[E0599]: no method named `test` found for reference `&[{integer}; 1]` in the current scope
3541
--> $DIR/auto-ref-slice-plus-ref.rs:11:12
3642
|
3743
LL | (&[1]).test();
3844
| ^^^^ method not found in `&[{integer}; 1]`
39-
...
40-
LL | trait MyIter {
41-
| ------------ `MyIter` defines an item `test`, perhaps you need to implement it
4245
|
4346
= help: items from traits can only be used if the trait is implemented and in scope
47+
note: `MyIter` defines an item `test`, perhaps you need to implement it
48+
--> $DIR/auto-ref-slice-plus-ref.rs:14:1
49+
|
50+
LL | trait MyIter {
51+
| ^^^^^^^^^^^^
4452

4553
error: aborting due to 4 previous errors
4654

src/test/ui/impl-trait/issues/issue-21659-show-relevant-trait-impls-3.stderr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
error[E0599]: no method named `foo` found for struct `Bar` in the current scope
22
--> $DIR/issue-21659-show-relevant-trait-impls-3.rs:20:8
33
|
4-
LL | trait Foo<A> {
5-
| ------------ `Foo` defines an item `foo`, perhaps you need to implement it
6-
...
74
LL | struct Bar;
85
| ----------- method `foo` not found for this
96
...
107
LL | f1.foo(1usize);
118
| ^^^ method not found in `Bar`
129
|
1310
= help: items from traits can only be used if the trait is implemented and in scope
11+
note: `Foo` defines an item `foo`, perhaps you need to implement it
12+
--> $DIR/issue-21659-show-relevant-trait-impls-3.rs:1:1
13+
|
14+
LL | trait Foo<A> {
15+
| ^^^^^^^^^^^^
1416

1517
error: aborting due to previous error
1618

src/test/ui/impl-trait/no-method-suggested-traits.stderr

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,68 +122,80 @@ LL | std::rc::Rc::new(&mut Box::new(&Foo)).method();
122122
error[E0599]: no method named `method2` found for type `u64` in the current scope
123123
--> $DIR/no-method-suggested-traits.rs:45:10
124124
|
125-
LL | pub trait Bar {
126-
| ------------- `foo::Bar` defines an item `method2`, perhaps you need to implement it
127-
...
128125
LL | 1u64.method2();
129126
| ^^^^^^^ method not found in `u64`
130127
|
131128
= help: items from traits can only be used if the trait is implemented and in scope
129+
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
130+
--> $DIR/no-method-suggested-traits.rs:8:5
131+
|
132+
LL | pub trait Bar {
133+
| ^^^^^^^^^^^^^
132134

133135
error[E0599]: no method named `method2` found for struct `std::rc::Rc<&mut std::boxed::Box<&u64>>` in the current scope
134136
--> $DIR/no-method-suggested-traits.rs:47:44
135137
|
136-
LL | pub trait Bar {
137-
| ------------- `foo::Bar` defines an item `method2`, perhaps you need to implement it
138-
...
139138
LL | std::rc::Rc::new(&mut Box::new(&1u64)).method2();
140139
| ^^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&u64>>`
141140
|
142141
= help: items from traits can only be used if the trait is implemented and in scope
142+
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
143+
--> $DIR/no-method-suggested-traits.rs:8:5
144+
|
145+
LL | pub trait Bar {
146+
| ^^^^^^^^^^^^^
143147

144148
error[E0599]: no method named `method2` found for struct `no_method_suggested_traits::Foo` in the current scope
145149
--> $DIR/no-method-suggested-traits.rs:50:37
146150
|
147-
LL | pub trait Bar {
148-
| ------------- `foo::Bar` defines an item `method2`, perhaps you need to implement it
149-
...
150151
LL | no_method_suggested_traits::Foo.method2();
151152
| ^^^^^^^ method not found in `no_method_suggested_traits::Foo`
152153
|
153154
= help: items from traits can only be used if the trait is implemented and in scope
155+
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
156+
--> $DIR/no-method-suggested-traits.rs:8:5
157+
|
158+
LL | pub trait Bar {
159+
| ^^^^^^^^^^^^^
154160

155161
error[E0599]: no method named `method2` found for struct `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Foo>>` in the current scope
156162
--> $DIR/no-method-suggested-traits.rs:52:71
157163
|
158-
LL | pub trait Bar {
159-
| ------------- `foo::Bar` defines an item `method2`, perhaps you need to implement it
160-
...
161164
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method2();
162165
| ^^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Foo>>`
163166
|
164167
= help: items from traits can only be used if the trait is implemented and in scope
168+
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
169+
--> $DIR/no-method-suggested-traits.rs:8:5
170+
|
171+
LL | pub trait Bar {
172+
| ^^^^^^^^^^^^^
165173

166174
error[E0599]: no method named `method2` found for enum `no_method_suggested_traits::Bar` in the current scope
167175
--> $DIR/no-method-suggested-traits.rs:54:40
168176
|
169-
LL | pub trait Bar {
170-
| ------------- `foo::Bar` defines an item `method2`, perhaps you need to implement it
171-
...
172177
LL | no_method_suggested_traits::Bar::X.method2();
173178
| ^^^^^^^ method not found in `no_method_suggested_traits::Bar`
174179
|
175180
= help: items from traits can only be used if the trait is implemented and in scope
181+
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
182+
--> $DIR/no-method-suggested-traits.rs:8:5
183+
|
184+
LL | pub trait Bar {
185+
| ^^^^^^^^^^^^^
176186

177187
error[E0599]: no method named `method2` found for struct `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Bar>>` in the current scope
178188
--> $DIR/no-method-suggested-traits.rs:56:74
179189
|
180-
LL | pub trait Bar {
181-
| ------------- `foo::Bar` defines an item `method2`, perhaps you need to implement it
182-
...
183190
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method2();
184191
| ^^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Bar>>`
185192
|
186193
= help: items from traits can only be used if the trait is implemented and in scope
194+
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
195+
--> $DIR/no-method-suggested-traits.rs:8:5
196+
|
197+
LL | pub trait Bar {
198+
| ^^^^^^^^^^^^^
187199

188200
error[E0599]: no method named `method3` found for struct `Foo` in the current scope
189201
--> $DIR/no-method-suggested-traits.rs:59:9

src/test/ui/issues/issue-50264-inner-deref-trait/option-as_deref.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ LL | let _result = &Some(42).as_deref();
55
| ^^^^^^^^ help: there is a method with a similar name: `as_ref`
66
|
77
= note: the method `as_deref` exists but the following trait bounds were not satisfied:
8-
`<{integer} as std::ops::Deref>::Target = _`
98
`{integer}: std::ops::Deref`
9+
`<{integer} as std::ops::Deref>::Target = _`
1010

1111
error: aborting due to previous error
1212

src/test/ui/issues/issue-50264-inner-deref-trait/option-as_deref_mut.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ LL | let _result = &mut Some(42).as_deref_mut();
55
| ^^^^^^^^^^^^ method not found in `std::option::Option<{integer}>`
66
|
77
= note: the method `as_deref_mut` exists but the following trait bounds were not satisfied:
8-
`<{integer} as std::ops::Deref>::Target = _`
98
`{integer}: std::ops::DerefMut`
9+
`<{integer} as std::ops::Deref>::Target = _`
1010

1111
error: aborting due to previous error
1212

src/test/ui/issues/issue-50264-inner-deref-trait/result-as_deref.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ LL | let _result = &Ok(42).as_deref();
55
| ^^^^^^^^ help: there is a method with a similar name: `as_ref`
66
|
77
= note: the method `as_deref` exists but the following trait bounds were not satisfied:
8-
`<{integer} as std::ops::Deref>::Target = _`
98
`{integer}: std::ops::Deref`
9+
`<{integer} as std::ops::Deref>::Target = _`
1010

1111
error: aborting due to previous error
1212

src/test/ui/issues/issue-50264-inner-deref-trait/result-as_deref_err.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ LL | let _result = &Err(41).as_deref_err();
55
| ^^^^^^^^^^^^ help: there is a method with a similar name: `as_deref_mut`
66
|
77
= note: the method `as_deref_err` exists but the following trait bounds were not satisfied:
8-
`<{integer} as std::ops::Deref>::Target = _`
98
`{integer}: std::ops::Deref`
9+
`<{integer} as std::ops::Deref>::Target = _`
1010

1111
error: aborting due to previous error
1212

src/test/ui/issues/issue-50264-inner-deref-trait/result-as_deref_mut.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ LL | let _result = &mut Ok(42).as_deref_mut();
55
| ^^^^^^^^^^^^ help: there is a method with a similar name: `as_deref_err`
66
|
77
= note: the method `as_deref_mut` exists but the following trait bounds were not satisfied:
8-
`<{integer} as std::ops::Deref>::Target = _`
98
`{integer}: std::ops::DerefMut`
9+
`<{integer} as std::ops::Deref>::Target = _`
1010

1111
error: aborting due to previous error
1212

src/test/ui/issues/issue-50264-inner-deref-trait/result-as_deref_mut_err.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ LL | let _result = &mut Err(41).as_deref_mut_err();
55
| ^^^^^^^^^^^^^^^^ help: there is a method with a similar name: `as_deref_mut`
66
|
77
= note: the method `as_deref_mut_err` exists but the following trait bounds were not satisfied:
8-
`<{integer} as std::ops::Deref>::Target = _`
98
`{integer}: std::ops::DerefMut`
9+
`<{integer} as std::ops::Deref>::Target = _`
1010

1111
error: aborting due to previous error
1212

src/test/ui/issues/issue-57362-1.stderr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
error[E0599]: no method named `f` found for fn pointer `fn(&u8)` in the current scope
22
--> $DIR/issue-57362-1.rs:20:7
33
|
4-
LL | trait Trait {
5-
| ----------- `Trait` defines an item `f`, perhaps you need to implement it
6-
...
74
LL | a.f();
85
| ^ method not found in `fn(&u8)`
96
|
107
= note: `a` is a function, perhaps you wish to call it
118
= help: items from traits can only be used if the trait is implemented and in scope
9+
note: `Trait` defines an item `f`, perhaps you need to implement it
10+
--> $DIR/issue-57362-1.rs:8:1
11+
|
12+
LL | trait Trait {
13+
| ^^^^^^^^^^^
1214

1315
error: aborting due to previous error
1416

src/test/ui/issues/issue-57362-2.stderr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
error[E0599]: no function or associated item named `make_g` found for fn pointer `for<'r> fn(&'r ())` in the current scope
22
--> $DIR/issue-57362-2.rs:22:25
33
|
4-
LL | trait X {
5-
| ------- `X` defines an item `make_g`, perhaps you need to implement it
6-
...
74
LL | let x = <fn (&())>::make_g();
85
| ^^^^^^ function or associated item not found in `for<'r> fn(&'r ())`
96
|
107
= help: items from traits can only be used if the trait is implemented and in scope
8+
note: `X` defines an item `make_g`, perhaps you need to implement it
9+
--> $DIR/issue-57362-2.rs:8:1
10+
|
11+
LL | trait X {
12+
| ^^^^^^^
1113

1214
error: aborting due to previous error
1315

src/test/ui/never_type/issue-2149.stderr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ LL | for elt in self { r = r + f(*elt); }
99
error[E0599]: no method named `bind` found for array `[&str; 1]` in the current scope
1010
--> $DIR/issue-2149.rs:13:12
1111
|
12-
LL | trait VecMonad<A> {
13-
| ----------------- `VecMonad` defines an item `bind`, perhaps you need to implement it
14-
...
1512
LL | ["hi"].bind(|x| [x] );
1613
| ^^^^ method not found in `[&str; 1]`
1714
|
1815
= help: items from traits can only be used if the trait is implemented and in scope
16+
note: `VecMonad` defines an item `bind`, perhaps you need to implement it
17+
--> $DIR/issue-2149.rs:1:1
18+
|
19+
LL | trait VecMonad<A> {
20+
| ^^^^^^^^^^^^^^^^^
1921

2022
error: aborting due to 2 previous errors
2123

src/test/ui/specialization/defaultimpl/specialization-trait-not-implemented.stderr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
error[E0599]: no method named `foo_one` found for struct `MyStruct` in the current scope
22
--> $DIR/specialization-trait-not-implemented.rs:22:29
33
|
4-
LL | trait Foo {
5-
| --------- `Foo` defines an item `foo_one`, perhaps you need to implement it
6-
...
74
LL | struct MyStruct;
85
| ----------------
96
| |
@@ -16,6 +13,11 @@ LL | println!("{}", MyStruct.foo_one());
1613
= note: the method `foo_one` exists but the following trait bounds were not satisfied:
1714
`MyStruct: Foo`
1815
= help: items from traits can only be used if the trait is implemented and in scope
16+
note: `Foo` defines an item `foo_one`, perhaps you need to implement it
17+
--> $DIR/specialization-trait-not-implemented.rs:7:1
18+
|
19+
LL | trait Foo {
20+
| ^^^^^^^^^
1921

2022
error: aborting due to previous error
2123

0 commit comments

Comments
 (0)