Skip to content

Commit

Permalink
keep predicate order and tweak output
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Feb 25, 2020
1 parent 529b891 commit a66599f
Show file tree
Hide file tree
Showing 19 changed files with 129 additions and 79 deletions.
16 changes: 11 additions & 5 deletions src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
},
})
})
.collect::<Vec<String>>();
.enumerate()
.collect::<Vec<(usize, String)>>();
for ((span, empty_where), obligations) in type_params.into_iter() {
err.span_suggestion_verbose(
span,
Expand All @@ -662,15 +663,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
}

bound_list.sort();
bound_list.dedup(); // #35677
bound_list.sort_by(|(_, a), (_, b)| a.cmp(&b)); // Sort alphabetically.
bound_list.dedup_by(|(_, a), (_, b)| a == b); // #35677
bound_list.sort_by_key(|(pos, _)| *pos); // Keep the original predicate order.
bound_spans.sort();
bound_spans.dedup();
for (span, msg) in bound_spans.into_iter() {
err.span_label(span, &msg);
}
if !bound_list.is_empty() {
let bound_list = bound_list.join("\n");
let bound_list = bound_list
.into_iter()
.map(|(_, path)| path)
.collect::<Vec<_>>()
.join("\n");
err.note(&format!(
"the method `{}` exists but the following trait bounds were not \
satisfied:\n{}",
Expand Down Expand Up @@ -1095,7 +1101,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut use_note = true;
if let [trait_info] = &candidates[..] {
if let Some(span) = self.tcx.hir().span_if_local(trait_info.def_id) {
err.span_label(
err.span_note(
self.tcx.sess.source_map().def_span(span),
&format!(
"`{}` defines an item `{}`, perhaps you need to {} it",
Expand Down
8 changes: 5 additions & 3 deletions src/test/ui/associated-const/associated-const-no-item.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
error[E0599]: no associated item named `ID` found for type `i32` in the current scope
--> $DIR/associated-const-no-item.rs:5:23
|
LL | trait Foo {
| --------- `Foo` defines an item `ID`, perhaps you need to implement it
...
LL | const X: i32 = <i32>::ID;
| ^^ associated item not found in `i32`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `Foo` defines an item `ID`, perhaps you need to implement it
--> $DIR/associated-const-no-item.rs:1:1
|
LL | trait Foo {
| ^^^^^^^^^

error: aborting due to previous error

Expand Down
32 changes: 20 additions & 12 deletions src/test/ui/auto-ref-slice-plus-ref.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,52 @@ error[E0599]: no method named `test_mut` found for struct `std::vec::Vec<{intege
|
LL | a.test_mut();
| ^^^^^^^^ help: there is a method with a similar name: `get_mut`
...
LL | trait MyIter {
| ------------ `MyIter` defines an item `test_mut`, perhaps you need to implement it
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `MyIter` defines an item `test_mut`, perhaps you need to implement it
--> $DIR/auto-ref-slice-plus-ref.rs:14:1
|
LL | trait MyIter {
| ^^^^^^^^^^^^

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

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

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

error: aborting due to 4 previous errors

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
error[E0599]: no method named `foo` found for struct `Bar` in the current scope
--> $DIR/issue-21659-show-relevant-trait-impls-3.rs:20:8
|
LL | trait Foo<A> {
| ------------ `Foo` defines an item `foo`, perhaps you need to implement it
...
LL | struct Bar;
| ----------- method `foo` not found for this
...
LL | f1.foo(1usize);
| ^^^ method not found in `Bar`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `Foo` defines an item `foo`, perhaps you need to implement it
--> $DIR/issue-21659-show-relevant-trait-impls-3.rs:1:1
|
LL | trait Foo<A> {
| ^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
48 changes: 30 additions & 18 deletions src/test/ui/impl-trait/no-method-suggested-traits.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -122,68 +122,80 @@ LL | std::rc::Rc::new(&mut Box::new(&Foo)).method();
error[E0599]: no method named `method2` found for type `u64` in the current scope
--> $DIR/no-method-suggested-traits.rs:45:10
|
LL | pub trait Bar {
| ------------- `foo::Bar` defines an item `method2`, perhaps you need to implement it
...
LL | 1u64.method2();
| ^^^^^^^ method not found in `u64`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
--> $DIR/no-method-suggested-traits.rs:8:5
|
LL | pub trait Bar {
| ^^^^^^^^^^^^^

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

error[E0599]: no method named `method2` found for struct `no_method_suggested_traits::Foo` in the current scope
--> $DIR/no-method-suggested-traits.rs:50:37
|
LL | pub trait Bar {
| ------------- `foo::Bar` defines an item `method2`, perhaps you need to implement it
...
LL | no_method_suggested_traits::Foo.method2();
| ^^^^^^^ method not found in `no_method_suggested_traits::Foo`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
--> $DIR/no-method-suggested-traits.rs:8:5
|
LL | pub trait Bar {
| ^^^^^^^^^^^^^

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
--> $DIR/no-method-suggested-traits.rs:52:71
|
LL | pub trait Bar {
| ------------- `foo::Bar` defines an item `method2`, perhaps you need to implement it
...
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method2();
| ^^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Foo>>`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
--> $DIR/no-method-suggested-traits.rs:8:5
|
LL | pub trait Bar {
| ^^^^^^^^^^^^^

error[E0599]: no method named `method2` found for enum `no_method_suggested_traits::Bar` in the current scope
--> $DIR/no-method-suggested-traits.rs:54:40
|
LL | pub trait Bar {
| ------------- `foo::Bar` defines an item `method2`, perhaps you need to implement it
...
LL | no_method_suggested_traits::Bar::X.method2();
| ^^^^^^^ method not found in `no_method_suggested_traits::Bar`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
--> $DIR/no-method-suggested-traits.rs:8:5
|
LL | pub trait Bar {
| ^^^^^^^^^^^^^

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
--> $DIR/no-method-suggested-traits.rs:56:74
|
LL | pub trait Bar {
| ------------- `foo::Bar` defines an item `method2`, perhaps you need to implement it
...
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method2();
| ^^^^^^^ method not found in `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Bar>>`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
--> $DIR/no-method-suggested-traits.rs:8:5
|
LL | pub trait Bar {
| ^^^^^^^^^^^^^

error[E0599]: no method named `method3` found for struct `Foo` in the current scope
--> $DIR/no-method-suggested-traits.rs:59:9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ LL | let _result = &Some(42).as_deref();
| ^^^^^^^^ help: there is a method with a similar name: `as_ref`
|
= note: the method `as_deref` exists but the following trait bounds were not satisfied:
`<{integer} as std::ops::Deref>::Target = _`
`{integer}: std::ops::Deref`
`<{integer} as std::ops::Deref>::Target = _`

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ LL | let _result = &mut Some(42).as_deref_mut();
| ^^^^^^^^^^^^ method not found in `std::option::Option<{integer}>`
|
= note: the method `as_deref_mut` exists but the following trait bounds were not satisfied:
`<{integer} as std::ops::Deref>::Target = _`
`{integer}: std::ops::DerefMut`
`<{integer} as std::ops::Deref>::Target = _`

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ LL | let _result = &Ok(42).as_deref();
| ^^^^^^^^ help: there is a method with a similar name: `as_ref`
|
= note: the method `as_deref` exists but the following trait bounds were not satisfied:
`<{integer} as std::ops::Deref>::Target = _`
`{integer}: std::ops::Deref`
`<{integer} as std::ops::Deref>::Target = _`

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ LL | let _result = &Err(41).as_deref_err();
| ^^^^^^^^^^^^ help: there is a method with a similar name: `as_deref_mut`
|
= note: the method `as_deref_err` exists but the following trait bounds were not satisfied:
`<{integer} as std::ops::Deref>::Target = _`
`{integer}: std::ops::Deref`
`<{integer} as std::ops::Deref>::Target = _`

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ LL | let _result = &mut Ok(42).as_deref_mut();
| ^^^^^^^^^^^^ help: there is a method with a similar name: `as_deref_err`
|
= note: the method `as_deref_mut` exists but the following trait bounds were not satisfied:
`<{integer} as std::ops::Deref>::Target = _`
`{integer}: std::ops::DerefMut`
`<{integer} as std::ops::Deref>::Target = _`

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ LL | let _result = &mut Err(41).as_deref_mut_err();
| ^^^^^^^^^^^^^^^^ help: there is a method with a similar name: `as_deref_mut`
|
= note: the method `as_deref_mut_err` exists but the following trait bounds were not satisfied:
`<{integer} as std::ops::Deref>::Target = _`
`{integer}: std::ops::DerefMut`
`<{integer} as std::ops::Deref>::Target = _`

error: aborting due to previous error

Expand Down
8 changes: 5 additions & 3 deletions src/test/ui/issues/issue-57362-1.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
error[E0599]: no method named `f` found for fn pointer `fn(&u8)` in the current scope
--> $DIR/issue-57362-1.rs:20:7
|
LL | trait Trait {
| ----------- `Trait` defines an item `f`, perhaps you need to implement it
...
LL | a.f();
| ^ method not found in `fn(&u8)`
|
= note: `a` is a function, perhaps you wish to call it
= help: items from traits can only be used if the trait is implemented and in scope
note: `Trait` defines an item `f`, perhaps you need to implement it
--> $DIR/issue-57362-1.rs:8:1
|
LL | trait Trait {
| ^^^^^^^^^^^

error: aborting due to previous error

Expand Down
8 changes: 5 additions & 3 deletions src/test/ui/issues/issue-57362-2.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
error[E0599]: no function or associated item named `make_g` found for fn pointer `for<'r> fn(&'r ())` in the current scope
--> $DIR/issue-57362-2.rs:22:25
|
LL | trait X {
| ------- `X` defines an item `make_g`, perhaps you need to implement it
...
LL | let x = <fn (&())>::make_g();
| ^^^^^^ function or associated item not found in `for<'r> fn(&'r ())`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `X` defines an item `make_g`, perhaps you need to implement it
--> $DIR/issue-57362-2.rs:8:1
|
LL | trait X {
| ^^^^^^^

error: aborting due to previous error

Expand Down
8 changes: 5 additions & 3 deletions src/test/ui/never_type/issue-2149.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ LL | for elt in self { r = r + f(*elt); }
error[E0599]: no method named `bind` found for array `[&str; 1]` in the current scope
--> $DIR/issue-2149.rs:13:12
|
LL | trait VecMonad<A> {
| ----------------- `VecMonad` defines an item `bind`, perhaps you need to implement it
...
LL | ["hi"].bind(|x| [x] );
| ^^^^ method not found in `[&str; 1]`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `VecMonad` defines an item `bind`, perhaps you need to implement it
--> $DIR/issue-2149.rs:1:1
|
LL | trait VecMonad<A> {
| ^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
error[E0599]: no method named `foo_one` found for struct `MyStruct` in the current scope
--> $DIR/specialization-trait-not-implemented.rs:22:29
|
LL | trait Foo {
| --------- `Foo` defines an item `foo_one`, perhaps you need to implement it
...
LL | struct MyStruct;
| ----------------
| |
Expand All @@ -16,6 +13,11 @@ LL | println!("{}", MyStruct.foo_one());
= note: the method `foo_one` exists but the following trait bounds were not satisfied:
`MyStruct: Foo`
= help: items from traits can only be used if the trait is implemented and in scope
note: `Foo` defines an item `foo_one`, perhaps you need to implement it
--> $DIR/specialization-trait-not-implemented.rs:7:1
|
LL | trait Foo {
| ^^^^^^^^^

error: aborting due to previous error

Expand Down
Loading

0 comments on commit a66599f

Please sign in to comment.