Skip to content

Commit 6f5a16b

Browse files
committedApr 14, 2018
fix error span
1 parent 0b72d48 commit 6f5a16b

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed
 

‎src/librustc_mir/borrow_check/mod.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,10 +1639,18 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
16391639
} else {
16401640
self.get_default_err_msg(place)
16411641
};
1642+
let sp = self.mir.source_info(locations[0]).span;
1643+
let mut to_suggest_span = String::new();
1644+
if let Ok(src) =
1645+
self.tcx.sess.codemap().span_to_snippet(sp) {
1646+
to_suggest_span = src[1..].to_string();
1647+
};
16421648
err_info = Some((
1643-
self.mir.source_info(locations[0]).span,
1649+
sp,
16441650
"consider changing this to be a \
1645-
mutable reference: `&mut`", item_msg,
1651+
mutable reference",
1652+
to_suggest_span,
1653+
item_msg,
16461654
self.get_primary_err_msg(base)));
16471655
}
16481656
},
@@ -1652,9 +1660,15 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
16521660
_ => {},
16531661
}
16541662

1655-
if let Some((err_help_span, err_help_stmt, item_msg, sec_span)) = err_info {
1663+
if let Some((err_help_span,
1664+
err_help_stmt,
1665+
to_suggest_span,
1666+
item_msg,
1667+
sec_span)) = err_info {
16561668
let mut err = self.tcx.cannot_assign(span, &item_msg, Origin::Mir);
1657-
err.span_suggestion(err_help_span, err_help_stmt, format!(""));
1669+
err.span_suggestion(err_help_span,
1670+
err_help_stmt,
1671+
format!("&mut {}", to_suggest_span));
16581672
if place != place_err {
16591673
err.span_label(span, sec_span);
16601674
}

‎src/test/ui/nll/issue-47388.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0594]: cannot assign to data in a `&` reference
22
--> $DIR/issue-47388.rs:18:5
33
|
44
LL | let fancy_ref = &(&mut fancy);
5-
| ------------- help: consider changing this to be a mutable reference: `&mut`
5+
| ------------- help: consider changing this to be a mutable reference: `&mut (&mut fancy)`
66
LL | fancy_ref.num = 6; //~ ERROR E0594
77
| ^^^^^^^^^^^^^^^^^ `fancy_ref` is a `&` reference, so the data it refers to cannot be written
88

0 commit comments

Comments
 (0)
Please sign in to comment.