Skip to content

Commit 7a90241

Browse files
committed
tweak "make mut" spans (No. 4)
1 parent 9329bb5 commit 7a90241

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1263,21 +1263,21 @@ fn suggest_ampmut<'tcx>(
12631263
{
12641264
let span = span.with_lo(span.lo() + BytePos(ws_pos as u32)).shrink_to_lo();
12651265
(true, span, " mut".to_owned())
1266+
// if there is already a binding, we modify it to be `mut`
12661267
} else if binding_exists {
12671268
// shrink the span to just after the `&` in `&variable`
12681269
let span = span.with_lo(span.lo() + BytePos(1)).shrink_to_lo();
12691270
(true, span, "mut ".to_owned())
1271+
// otherwise, suggest that the user annotates the binding; we provide the
1272+
// type of the local.
12701273
} else {
12711274
let ty_mut = local_decl.ty.builtin_deref(true).unwrap();
12721275
assert_eq!(ty_mut.mutbl, hir::Mutability::Not);
1276+
12731277
(
1274-
binding_exists,
1278+
false,
12751279
span,
1276-
if local_decl.ty.is_ref() {
1277-
format!("&mut {}", ty_mut.ty)
1278-
} else {
1279-
format!("*mut {}", ty_mut.ty)
1280-
},
1280+
format!("{}mut {}", if local_decl.ty.is_ref() {"&"} else {"*"}, ty_mut.ty)
12811281
)
12821282
}
12831283
}

0 commit comments

Comments
 (0)