mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 03:38:29 +00:00
tweak "make mut" spans (No. 4)
This commit is contained in:
parent
57c6a3183c
commit
336a6569f5
@ -1263,21 +1263,21 @@ fn suggest_ampmut<'tcx>(
|
|||||||
{
|
{
|
||||||
let span = span.with_lo(span.lo() + BytePos(ws_pos as u32)).shrink_to_lo();
|
let span = span.with_lo(span.lo() + BytePos(ws_pos as u32)).shrink_to_lo();
|
||||||
(true, span, " mut".to_owned())
|
(true, span, " mut".to_owned())
|
||||||
|
// if there is already a binding, we modify it to be `mut`
|
||||||
} else if binding_exists {
|
} else if binding_exists {
|
||||||
// shrink the span to just after the `&` in `&variable`
|
// shrink the span to just after the `&` in `&variable`
|
||||||
let span = span.with_lo(span.lo() + BytePos(1)).shrink_to_lo();
|
let span = span.with_lo(span.lo() + BytePos(1)).shrink_to_lo();
|
||||||
(true, span, "mut ".to_owned())
|
(true, span, "mut ".to_owned())
|
||||||
|
// otherwise, suggest that the user annotates the binding; we provide the
|
||||||
|
// type of the local.
|
||||||
} else {
|
} else {
|
||||||
let ty_mut = local_decl.ty.builtin_deref(true).unwrap();
|
let ty_mut = local_decl.ty.builtin_deref(true).unwrap();
|
||||||
assert_eq!(ty_mut.mutbl, hir::Mutability::Not);
|
assert_eq!(ty_mut.mutbl, hir::Mutability::Not);
|
||||||
|
|
||||||
(
|
(
|
||||||
binding_exists,
|
false,
|
||||||
span,
|
span,
|
||||||
if local_decl.ty.is_ref() {
|
format!("{}mut {}", if local_decl.ty.is_ref() {"&"} else {"*"}, ty_mut.ty)
|
||||||
format!("&mut {}", ty_mut.ty)
|
|
||||||
} else {
|
|
||||||
format!("*mut {}", ty_mut.ty)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user