diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 9844377d0bd32..b971ae02cd0bd 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -59,19 +59,33 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, (&ty::ExplicitSelfCategory::Static, &ty::ExplicitSelfCategory::Static) => {} (&ty::ExplicitSelfCategory::Static, _) => { - span_err!(tcx.sess, impl_m_span, E0185, + let mut err = struct_span_err!(tcx.sess, impl_m_span, E0185, "method `{}` has a `{}` declaration in the impl, \ but not in the trait", trait_m.name, impl_m.explicit_self); + err.span_label(impl_m_span, &format!("`{}` used in impl", + impl_m.explicit_self)); + if let Some(span) = tcx.map.span_if_local(trait_m.def_id) { + err.span_label(span, &format!("trait declared without `{}`", + impl_m.explicit_self)); + } + err.emit(); return; } (_, &ty::ExplicitSelfCategory::Static) => { - span_err!(tcx.sess, impl_m_span, E0186, + let mut err = struct_span_err!(tcx.sess, impl_m_span, E0186, "method `{}` has a `{}` declaration in the trait, \ but not in the impl", trait_m.name, trait_m.explicit_self); + err.span_label(impl_m_span, &format!("expected `{}` in impl", + trait_m.explicit_self)); + if let Some(span) = tcx.map.span_if_local(trait_m.def_id) { + err.span_label(span, & format!("`{}` used in trait", + trait_m.explicit_self)); + } + err.emit(); return; } _ => { diff --git a/src/test/compile-fail/E0185.rs b/src/test/compile-fail/E0185.rs index 0e33687a84dfb..be54c3754ea1f 100644 --- a/src/test/compile-fail/E0185.rs +++ b/src/test/compile-fail/E0185.rs @@ -9,13 +9,14 @@ // except according to those terms. trait Foo { - fn foo(); + fn foo(); //~ trait declared without `&self` } struct Bar; impl Foo for Bar { fn foo(&self) {} //~ ERROR E0185 + //~^ `&self` used in impl } fn main() { diff --git a/src/test/compile-fail/E0186.rs b/src/test/compile-fail/E0186.rs index aa0a38bedcb54..55a3490cac4a6 100644 --- a/src/test/compile-fail/E0186.rs +++ b/src/test/compile-fail/E0186.rs @@ -9,13 +9,14 @@ // except according to those terms. trait Foo { - fn foo(&self); + fn foo(&self); //~ `&self` used in trait } struct Bar; impl Foo for Bar { fn foo() {} //~ ERROR E0186 + //~^ expected `&self` in impl } fn main() {