Rollup merge of #49931 - csmoe:end_span, r=estebank
Fix incorrect span in `&mut` suggestion Fixes #49859
This commit is contained in:
commit
73ea8939ee
2 changed files with 19 additions and 5 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue