diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 2fc4b3bea58b..4d4e91913785 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -297,7 +297,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { tcx.sess.diagnostic().struct_dummy() }; - if let Some(def) = actual.ty_adt_def() { + if let Some(def) = actual.ty_adt_def() { if let Some(full_sp) = tcx.hir.span_if_local(def.did) { let def_sp = tcx.sess.codemap().def_span(full_sp); err.span_label(def_sp, format!("{} `{}` not found {}", @@ -380,6 +380,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if !static_sources.is_empty() { err.note("found the following associated functions; to be used as methods, \ functions must have a `self` parameter"); + err.span_label(span, "this is an associated function, not a method"); } if static_sources.len() == 1 { if let Some(expr) = rcvr_expr { diff --git a/src/test/ui/span/issue-7575.stderr b/src/test/ui/span/issue-7575.stderr index 3ae784b32a4e..1061a8d96815 100644 --- a/src/test/ui/span/issue-7575.stderr +++ b/src/test/ui/span/issue-7575.stderr @@ -2,7 +2,7 @@ error[E0599]: no method named `f9` found for type `usize` in the current scope --> $DIR/issue-7575.rs:74:18 | LL | u.f8(42) + u.f9(342) + m.fff(42) - | ^^ + | ^^ this is an associated function, not a method | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: candidate #1 is defined in the trait `CtxtFn` @@ -37,7 +37,8 @@ LL | struct Myisize(isize); ... LL | u.f8(42) + u.f9(342) + m.fff(42) | --^^^ - | | + | | | + | | this is an associated function, not a method | help: use associated function syntax intead: `Myisize::fff` | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter @@ -51,7 +52,7 @@ error[E0599]: no method named `is_str` found for type `T` in the current scope --> $DIR/issue-7575.rs:82:7 | LL | t.is_str() - | ^^^^^^ + | ^^^^^^ this is an associated function, not a method | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in the trait `ManyImplTrait`