Skip to content
Merged
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
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ pub(crate) struct NoAssociatedItem<'tcx> {
)]
pub(crate) struct CandidateTraitNote {
#[primary_span]
pub span: Span,
pub span: MultiSpan,
pub trait_name: String,
pub item_name: Ident,
pub action_or_ty: String,
Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4735,8 +4735,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if impls_trait(trait_info.def_id) {
self.suggest_valid_traits(err, item_name, vec![trait_info.def_id], false);
} else {
let mut span: MultiSpan = self.tcx.def_span(trait_info.def_id).into();
for assoc in self
.tcx
.associated_items(trait_info.def_id)
.filter_by_name_unhygienic(item_name.name)
{
span.push_span_context(self.tcx.def_span(assoc.def_id).shrink_to_lo());
}
err.subdiagnostic(CandidateTraitNote {
span: self.tcx.def_span(trait_info.def_id),
span,
trait_name: self.tcx.def_path_str(trait_info.def_id),
item_name,
action_or_ty: if trait_missing_method {
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/associated-consts/associated-const-no-item.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ note: `Foo` defines an item `ID`, perhaps you need to implement it
|
LL | trait Foo {
| ^^^^^^^^^
LL | const ID: i32;
|

error: aborting due to 1 previous error

Expand Down
6 changes: 6 additions & 0 deletions tests/ui/delegation/inherent-impls-self-replacement.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ note: `Trait` defines an item `get_s`, perhaps you need to implement it
|
LL | trait Trait: Sized {
| ^^^^^^^^^^^^^^^^^^
LL | fn get_s(self) -> S<(), 123>;
|

error[E0599]: no method named `get_s` found for struct `Rc<Self>` in the current scope
--> $DIR/inherent-impls-self-replacement.rs:49:38
Expand All @@ -122,6 +124,8 @@ note: `Trait` defines an item `get_s`, perhaps you need to implement it
|
LL | trait Trait: Sized {
| ^^^^^^^^^^^^^^^^^^
LL | fn get_s(self) -> S<(), 123>;
|

error[E0599]: no method named `get_s` found for struct `Pin<Box<Self>>` in the current scope
--> $DIR/inherent-impls-self-replacement.rs:51:39
Expand All @@ -135,6 +139,8 @@ note: `Trait` defines an item `get_s`, perhaps you need to implement it
|
LL | trait Trait: Sized {
| ^^^^^^^^^^^^^^^^^^
LL | fn get_s(self) -> S<(), 123>;
|

error[E0507]: cannot move out of `*self` which is behind a shared reference
--> $DIR/inherent-impls-self-replacement.rs:24:34
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ note: `ProviderExt` defines an item `request`, perhaps you need to implement it
|
LL | pub trait ProviderExt {
| ^^^^^^^^^^^^^^^^^^^^^
LL | fn request<R>(&self) {
|

error: aborting due to 1 previous error

Expand Down
3 changes: 3 additions & 0 deletions tests/ui/functions-closures/fn-help-with-err.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ note: `Bar` defines an item `bar`, perhaps you need to implement it
|
LL | trait Bar {
| ^^^^^^^^^
LL |
LL | fn bar(&self) {}
|
help: use parentheses to call this closure
|
LL | arc2().bar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ note: `M` defines an item `f`, perhaps you need to implement it
|
LL | trait M {
| ^^^^^^^
LL | fn f(&self) {}
|

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ note: `X` defines an item `make_g`, perhaps you need to implement it
|
LL | trait X {
| ^^^^^^^
LL | type G;
LL | fn make_g() -> Self::G;
|

error: implementation of `X` is not general enough
--> $DIR/hrtb-fn-ptr-impl-not-general-enough-57936.rs:26:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ note: `StreamExt` defines an item `filterx`, perhaps you need to implement it
|
LL | pub trait StreamExt
| ^^^^^^^^^^^^^^^^^^^
...
LL | fn filterx<F>(self, func: F) -> Filter<Self, F>
|

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ note: `StreamExt` defines an item `countx`, perhaps you need to implement it
|
LL | pub trait StreamExt
| ^^^^^^^^^^^^^^^^^^^
...
LL | fn countx(mut self) -> usize
= note: the full name for the type has been written to '$TEST_BUILD_DIR/hrtb-doesnt-borrow-self-2.long-type-$LONG_TYPE_HASH.txt'
= note: consider using `--verbose` to print the full type name to the console

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ note: `MyDebug` defines an item `my_debug`, perhaps you need to implement it
|
LL | trait MyDebug {
| ^^^^^^^^^^^^^
LL | fn my_debug(&self);
|

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ note: `MyDebug` defines an item `my_debug`, perhaps you need to implement it
|
LL | trait MyDebug {
| ^^^^^^^^^^^^^
LL | fn my_debug(&self);
|

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ note: `MyDebug` defines an item `my_debug`, perhaps you need to implement it
|
LL | trait MyDebug {
| ^^^^^^^^^^^^^
LL | fn my_debug(&self);
|

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ note: `Foo` defines an item `foo`, perhaps you need to implement it
|
LL | trait Foo<A> {
| ^^^^^^^^^^^^
LL | fn foo(&self, a: A) -> A {
|

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ note: `Trait` defines an item `method`, perhaps you need to implement it
|
LL | trait Trait: Sized {
| ^^^^^^^^^^^^^^^^^^
LL | fn method(self) {}
|

error[E0599]: no method named `method` found for reference `&impl Sized` in the current scope
--> $DIR/would-constrain-opaque.rs:32:11
Expand All @@ -23,6 +25,8 @@ note: `Trait` defines an item `method`, perhaps you need to implement it
|
LL | trait Trait: Sized {
| ^^^^^^^^^^^^^^^^^^
LL | fn method(self) {}
|

error: aborting due to 2 previous errors

Expand Down
18 changes: 18 additions & 0 deletions tests/ui/impl-trait/no-method-suggested-traits.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
|
LL | pub trait Bar {
| ^^^^^^^^^^^^^
...
LL | fn method2(&self) {}
|

error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&u64>>` in the current scope
--> $DIR/no-method-suggested-traits.rs:50:44
Expand All @@ -160,6 +163,9 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
|
LL | pub trait Bar {
| ^^^^^^^^^^^^^
...
LL | fn method2(&self) {}
|

error[E0599]: no method named `method2` found for struct `no_method_suggested_traits::Foo` in the current scope
--> $DIR/no-method-suggested-traits.rs:53:37
Expand All @@ -173,6 +179,9 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
|
LL | pub trait Bar {
| ^^^^^^^^^^^^^
...
LL | fn method2(&self) {}
|

error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&no_method_suggested_traits::Foo>>` in the current scope
--> $DIR/no-method-suggested-traits.rs:55:71
Expand All @@ -186,6 +195,9 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
|
LL | pub trait Bar {
| ^^^^^^^^^^^^^
...
LL | fn method2(&self) {}
|

error[E0599]: no method named `method2` found for enum `no_method_suggested_traits::Bar` in the current scope
--> $DIR/no-method-suggested-traits.rs:57:40
Expand All @@ -199,6 +211,9 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
|
LL | pub trait Bar {
| ^^^^^^^^^^^^^
...
LL | fn method2(&self) {}
|

error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&no_method_suggested_traits::Bar>>` in the current scope
--> $DIR/no-method-suggested-traits.rs:59:74
Expand All @@ -212,6 +227,9 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
|
LL | pub trait Bar {
| ^^^^^^^^^^^^^
...
LL | fn method2(&self) {}
|

error[E0599]: no method named `method3` found for struct `Foo` in the current scope
--> $DIR/no-method-suggested-traits.rs:62:9
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/iterators/iterator-does-not-need-into-iter.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ note: `HasMethod` defines an item `foo`, perhaps you need to implement it
|
LL | trait HasMethod {
| ^^^^^^^^^^^^^^^
LL | fn foo(self);
|

error: aborting due to 1 previous error

Expand Down
4 changes: 4 additions & 0 deletions tests/ui/methods/tuple-suggestions-issue-142488.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ note: `Trait` defines an item `meth`, perhaps you need to implement it
|
LL | trait Trait {
| ^^^^^^^^^^^
LL | fn meth(self);
|

error[E0599]: the method `f` exists for tuple `(_,)`, but its trait bounds were not satisfied
--> $DIR/tuple-suggestions-issue-142488.rs:46:16
Expand All @@ -54,6 +56,8 @@ note: `Tr` defines an item `f`, perhaps you need to implement it
|
LL | trait Tr {
| ^^^^^^^^
LL | fn f<A>(self) -> (A,)
|

error: aborting due to 4 previous errors

Expand Down
11 changes: 11 additions & 0 deletions tests/ui/methods/vec-autoderef-autoref.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ note: `MyIter` defines an item `test_mut`, perhaps you need to implement it
|
LL | trait MyIter {
| ^^^^^^^^^^^^
LL | fn test_mut(&mut self);
|
help: there is a method `get_mut` with a similar name, but with different arguments
--> $SRC_DIR/core/src/slice/mod.rs:LL:COL

Expand All @@ -25,6 +27,9 @@ note: `MyIter` defines an item `test`, perhaps you need to implement it
|
LL | trait MyIter {
| ^^^^^^^^^^^^
LL | fn test_mut(&mut self);
LL | fn test(&self);
|

error[E0599]: no method named `test` found for array `[{integer}; 1]` in the current scope
--> $DIR/vec-autoderef-autoref.rs:9:11
Expand All @@ -38,6 +43,9 @@ note: `MyIter` defines an item `test`, perhaps you need to implement it
|
LL | trait MyIter {
| ^^^^^^^^^^^^
LL | fn test_mut(&mut self);
LL | fn test(&self);
|

error[E0599]: no method named `test` found for reference `&[{integer}; 1]` in the current scope
--> $DIR/vec-autoderef-autoref.rs:10:12
Expand All @@ -51,6 +59,9 @@ note: `MyIter` defines an item `test`, perhaps you need to implement it
|
LL | trait MyIter {
| ^^^^^^^^^^^^
LL | fn test_mut(&mut self);
LL | fn test(&self);
|

error: aborting due to 4 previous errors

Expand Down
2 changes: 2 additions & 0 deletions tests/ui/nll/issue-57362-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ note: `Trait` defines an item `f`, perhaps you need to implement it
|
LL | trait Trait {
| ^^^^^^^^^^^
LL | fn f(self);
|

error: aborting due to 1 previous error

Expand Down
3 changes: 3 additions & 0 deletions tests/ui/nll/issue-57362-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ note: `X` defines an item `make_g`, perhaps you need to implement it
|
LL | trait X {
| ^^^^^^^
LL | type G;
LL | fn make_g() -> Self::G;
|

error: aborting due to 1 previous error

Expand Down
6 changes: 6 additions & 0 deletions tests/ui/nll/issue-57642-higher-ranked-subtype.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ note: `X` defines an item `make_g`, perhaps you need to implement it
|
LL | trait X {
| ^^^^^^^
LL | type G;
LL | fn make_g() -> Self::G;
|

error[E0599]: no associated function or constant named `make_f` found for fn pointer `for<'a> fn(&'a ())` in the current scope
--> $DIR/issue-57642-higher-ranked-subtype.rs:36:25
Expand All @@ -23,6 +26,9 @@ note: `Y` defines an item `make_f`, perhaps you need to implement it
|
LL | trait Y {
| ^^^^^^^
LL | type F;
LL | fn make_f() -> Self::F;
|

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ note: `Set` defines an item `contains`, perhaps you need to implement it
|
LL | trait Set<T> {
| ^^^^^^^^^^^^
LL | fn contains(&self, bit: T);
|

error: aborting due to 4 previous errors

Expand Down
2 changes: 2 additions & 0 deletions tests/ui/specialization/default-impl-not-an-impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ note: `Foo` defines an item `f`, perhaps you need to implement it
|
LL | trait Foo {
| ^^^^^^^^^
LL | fn f(&self) -> u32;
|

error[E0277]: the trait bound `u32: Foo` is not satisfied
--> $DIR/default-impl-not-an-impl.rs:65:23
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ note: `Foo` defines an item `foo_one`, perhaps you need to implement it
|
LL | trait Foo {
| ^^^^^^^^^
LL | fn foo_one(&self) -> &'static str;
|

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ note: `Foo` defines an item `foo`, perhaps you need to implement it
|
LL | trait Foo {
| ^^^^^^^^^
LL | fn foo(&self);
= note: the trait `FooBar` defines an item `foo`, but is explicitly unimplemented

error: aborting due to 4 previous errors
Expand Down
Loading
Loading