about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2017-03-12 13:49:28 -0700
committerEsteban Küber <esteban@kuber.com.ar>2017-03-12 16:38:53 -0700
commit38b5b29c57fc86aae5a1bc8d1319cc08907d9ee0 (patch)
tree0c99342d0ccdef39de663ff165047772e3fecdc1
parent6ba494b68bede3bd8d1288f53137c8895260bec7 (diff)
downloadrust-38b5b29c57fc86aae5a1bc8d1319cc08907d9ee0.tar.gz
rust-38b5b29c57fc86aae5a1bc8d1319cc08907d9ee0.zip
Change label to "consider changing this to `mut f`"
Change the wording of mutable borrow on immutable binding from "this
should be `mut`" to "consider changing this to `mut f`".
-rw-r--r--src/librustc_borrowck/borrowck/mod.rs4
-rw-r--r--src/test/ui/did_you_mean/issue-39544.stderr2
2 files changed, 4 insertions, 2 deletions
diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs
index 04036d6c6b9..073ebe24de9 100644
--- a/src/librustc_borrowck/borrowck/mod.rs
+++ b/src/librustc_borrowck/borrowck/mod.rs
@@ -748,7 +748,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
             db.span_label(span, &msg);
         }
         if let Some(span) = local_def {
-            db.span_label(span, &"this should be `mut`");
+            if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(span) {
+                db.span_label(span, &format!("consider changing this to `mut {}`", snippet));
+            }
         }
         db
     }
diff --git a/src/test/ui/did_you_mean/issue-39544.stderr b/src/test/ui/did_you_mean/issue-39544.stderr
index 1cd322efab5..3eb3e9a4c3b 100644
--- a/src/test/ui/did_you_mean/issue-39544.stderr
+++ b/src/test/ui/did_you_mean/issue-39544.stderr
@@ -2,7 +2,7 @@ error: cannot borrow immutable field `z.x` as mutable
   --> $DIR/issue-39544.rs:21:18
    |
 20 |     let z = Z { x: X::Y };
-   |         - this should be `mut`
+   |         - consider changing this to `mut z`
 21 |     let _ = &mut z.x;
    |                  ^^^