about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-04-17 01:51:01 +0800
committerkennytm <kennytm@gmail.com>2018-04-17 03:34:30 +0800
commit73ea8939ee3480f8605360e1ec88b4b86a9f2c8b (patch)
treece2b295581c065067d18e4934226d1b413da2dd3
parente4991b2f48c02d2fc278c5018103530c1e4577e6 (diff)
parent6f5a16bf1e23d885fd898d430be3cc07eb572163 (diff)
downloadrust-73ea8939ee3480f8605360e1ec88b4b86a9f2c8b.tar.gz
rust-73ea8939ee3480f8605360e1ec88b4b86a9f2c8b.zip
Rollup merge of #49931 - csmoe:end_span, r=estebank
Fix incorrect span in `&mut` suggestion

Fixes #49859
-rw-r--r--src/librustc_mir/borrow_check/mod.rs22
-rw-r--r--src/test/ui/nll/issue-47388.stderr2
2 files changed, 19 insertions, 5 deletions
diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs
index 62acdf76546..87379651c23 100644
--- a/src/librustc_mir/borrow_check/mod.rs
+++ b/src/librustc_mir/borrow_check/mod.rs
@@ -1639,10 +1639,18 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
                                             } else {
                                                 self.get_default_err_msg(place)
                                             };
+                                            let sp = self.mir.source_info(locations[0]).span;
+                                            let mut to_suggest_span = String::new();
+                                            if let Ok(src) =
+                                                self.tcx.sess.codemap().span_to_snippet(sp) {
+                                                    to_suggest_span = src[1..].to_string();
+                                            };
                                             err_info = Some((
-                                                self.mir.source_info(locations[0]).span,
+                                                    sp,
                                                     "consider changing this to be a \
-                                                    mutable reference: `&mut`", item_msg,
+                                                    mutable reference",
+                                                    to_suggest_span,
+                                                    item_msg,
                                                     self.get_primary_err_msg(base)));
                                         }
                                 },
@@ -1652,9 +1660,15 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
                         _ => {},
                     }
 
-                    if let Some((err_help_span, err_help_stmt, item_msg, sec_span)) = err_info {
+                    if let Some((err_help_span,
+                                 err_help_stmt,
+                                 to_suggest_span,
+                                 item_msg,
+                                 sec_span)) = err_info {
                         let mut err = self.tcx.cannot_assign(span, &item_msg, Origin::Mir);
-                        err.span_suggestion(err_help_span, err_help_stmt, format!(""));
+                        err.span_suggestion(err_help_span,
+                                            err_help_stmt,
+                                            format!("&mut {}", to_suggest_span));
                         if place != place_err {
                             err.span_label(span, sec_span);
                         }
diff --git a/src/test/ui/nll/issue-47388.stderr b/src/test/ui/nll/issue-47388.stderr
index 272cb6510aa..f3952c49a2a 100644
--- a/src/test/ui/nll/issue-47388.stderr
+++ b/src/test/ui/nll/issue-47388.stderr
@@ -2,7 +2,7 @@ error[E0594]: cannot assign to data in a `&` reference
   --> $DIR/issue-47388.rs:18:5
    |
 LL |     let fancy_ref = &(&mut fancy);
-   |                     ------------- help: consider changing this to be a mutable reference: `&mut`
+   |                     ------------- help: consider changing this to be a mutable reference: `&mut (&mut fancy)`
 LL |     fancy_ref.num = 6; //~ ERROR E0594
    |     ^^^^^^^^^^^^^^^^^ `fancy_ref` is a `&` reference, so the data it refers to cannot be written