Rollup merge of #52702 - csmoe:mut_diff, r=estebank
Suggest fix when encountering different mutability from impl to trait Closes https://github.com/rust-lang/rust/issues/52412 r? @estebank
This commit is contained in:
commit
80c798b982
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue