about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEzra Shaw <ezrasure@outlook.com>2023-04-19 20:00:49 +1200
committerEzra Shaw <ezrashawdev@gmail.com>2023-05-05 22:40:05 +1200
commit336a6569f5477d36151500bbd7c57e3bba357cec (patch)
treece8b6669ba001b9a0811e108674be6d0ade139ec
parent57c6a3183c17e9f889adda1faca894a7cd692b02 (diff)
downloadrust-336a6569f5477d36151500bbd7c57e3bba357cec.tar.gz
rust-336a6569f5477d36151500bbd7c57e3bba357cec.zip
tweak "make mut" spans (No. 4)
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
index 50f9e7095f9..e842afced81 100644
--- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
@@ -1263,21 +1263,21 @@ fn suggest_ampmut<'tcx>(
     {
         let span = span.with_lo(span.lo() + BytePos(ws_pos as u32)).shrink_to_lo();
         (true, span, " mut".to_owned())
+    // if there is already a binding, we modify it to be `mut`
     } else if binding_exists {
         // shrink the span to just after the `&` in `&variable`
         let span = span.with_lo(span.lo() + BytePos(1)).shrink_to_lo();
         (true, span, "mut ".to_owned())
+    // otherwise, suggest that the user annotates the binding; we provide the
+    // type of the local.
     } else {
         let ty_mut = local_decl.ty.builtin_deref(true).unwrap();
         assert_eq!(ty_mut.mutbl, hir::Mutability::Not);
+
         (
-            binding_exists,
+            false,
             span,
-            if local_decl.ty.is_ref() {
-                format!("&mut {}", ty_mut.ty)
-            } else {
-                format!("*mut {}", ty_mut.ty)
-            },
+            format!("{}mut {}", if local_decl.ty.is_ref() {"&"} else {"*"}, ty_mut.ty)
         )
     }
 }