From 38b5b29c57fc86aae5a1bc8d1319cc08907d9ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 12 Mar 2017 13:49:28 -0700 Subject: [PATCH] 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`". --- src/librustc_borrowck/borrowck/mod.rs | 4 +++- src/test/ui/did_you_mean/issue-39544.stderr | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 04036d6c6b9e..073ebe24de92 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 1cd322efab57..3eb3e9a4c3b0 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; | ^^^