diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 220dd122b2679..55aa38d942efb 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -319,6 +319,17 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, E0053, "method `{}` has an incompatible type for trait", trait_m.ident); + if let TypeError::Mutability = terr { + if let Some(trait_err_span) = trait_err_span { + if let Ok(trait_err_str) = tcx.sess.codemap().span_to_snippet(trait_err_span) { + diag.span_suggestion( + impl_err_span, + "consider change the type to match the mutability in trait", + format!("{}", trait_err_str), + ); + } + } + } infcx.note_type_err(&mut diag, &cause, diff --git a/src/test/ui/issue-13033.stderr b/src/test/ui/issue-13033.stderr index 2db3cb80a819e..f06d7360d85b0 100644 --- a/src/test/ui/issue-13033.stderr +++ b/src/test/ui/issue-13033.stderr @@ -9,6 +9,10 @@ LL | fn bar(&mut self, other: &Foo) {} | = note: expected type `fn(&mut Baz, &mut dyn Foo)` found type `fn(&mut Baz, &dyn Foo)` +help: consider change the type to match the mutability in trait + | +LL | fn bar(&mut self, other: &mut Foo) {} + | ^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/mismatched_types/E0053.stderr b/src/test/ui/mismatched_types/E0053.stderr index 1b16694bf2c4d..f707a600f29e3 100644 --- a/src/test/ui/mismatched_types/E0053.stderr +++ b/src/test/ui/mismatched_types/E0053.stderr @@ -21,6 +21,10 @@ LL | fn bar(&mut self) { } | = note: expected type `fn(&Bar)` found type `fn(&mut Bar)` +help: consider change the type to match the mutability in trait + | +LL | fn bar(&self) { } + | ^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/mismatched_types/trait-impl-fn-incompatibility.stderr b/src/test/ui/mismatched_types/trait-impl-fn-incompatibility.stderr index 28b16641e4dd5..631af21cac5ca 100644 --- a/src/test/ui/mismatched_types/trait-impl-fn-incompatibility.stderr +++ b/src/test/ui/mismatched_types/trait-impl-fn-incompatibility.stderr @@ -21,6 +21,10 @@ LL | fn bar(&mut self, bar: &Bar) { } //~ ERROR incompatible type | = note: expected type `fn(&mut Bar, &mut Bar)` found type `fn(&mut Bar, &Bar)` +help: consider change the type to match the mutability in trait + | +LL | fn bar(&mut self, bar: &mut Bar) { } //~ ERROR incompatible type + | ^^^^^^^^ error: aborting due to 2 previous errors