More accurate mutability suggestion
This commit is contained in:
@@ -408,10 +408,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
fn_decl.implicit_self,
|
||||
hir::ImplicitSelfKind::RefImm | hir::ImplicitSelfKind::RefMut
|
||||
) {
|
||||
err.span_suggestion(
|
||||
upvar_ident.span,
|
||||
err.span_suggestion_verbose(
|
||||
upvar_ident.span.shrink_to_lo(),
|
||||
"consider changing this to be mutable",
|
||||
format!("mut {}", upvar_ident.name),
|
||||
"mut ",
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
break;
|
||||
@@ -419,10 +419,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err.span_suggestion(
|
||||
upvar_ident.span,
|
||||
err.span_suggestion_verbose(
|
||||
upvar_ident.span.shrink_to_lo(),
|
||||
"consider changing this to be mutable",
|
||||
format!("mut {}", upvar_ident.name),
|
||||
"mut ",
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
@@ -755,13 +755,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
||||
pat: hir::Pat { kind: hir::PatKind::Ref(_, _), .. },
|
||||
..
|
||||
}) = node
|
||||
&& let Ok(name) =
|
||||
self.infcx.tcx.sess.source_map().span_to_snippet(local_decl.source_info.span)
|
||||
{
|
||||
err.span_suggestion(
|
||||
pat_span,
|
||||
err.multipart_suggestion(
|
||||
"consider changing this to be mutable",
|
||||
format!("&(mut {name})"),
|
||||
vec![
|
||||
(pat_span.until(local_decl.source_info.span), "&(mut ".to_string()),
|
||||
(
|
||||
local_decl.source_info.span.shrink_to_hi().with_hi(pat_span.hi()),
|
||||
")".to_string(),
|
||||
),
|
||||
],
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user