lint with ref_span

This commit is contained in:
csmoe 2018-06-01 12:08:31 +08:00 committed by ashtneoi
parent 4e5d22889b
commit 1662daa23d
2 changed files with 6 additions and 8 deletions

View File

@ -1209,14 +1209,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
let let_span = self.tcx.hir.span(node_id);
match self.local_binding_mode(node_id) {
ty::BindByReference(..) => {
let snippet = self.tcx.sess.codemap().span_to_snippet(let_span);
if let Ok(snippet) = snippet {
let ref_span = self.tcx.sess.codemap().span_until_whitespace(let_span);
if let Ok(_) = self.tcx.sess.codemap().span_to_snippet(let_span) {
db.span_label(
let_span,
format!("consider changing this to `{}`",
snippet.replacen("ref ", "ref mut ", 1))
);
}
ref_span,
format!("consider changing this to `{}`", "ref mut"));
};
}
ty::BindByValue(..) => {
if let (Some(local_ty), is_implicit_self) = self.local_ty(node_id) {

View File

@ -2,7 +2,7 @@ error[E0594]: cannot assign to immutable borrowed content `*my_ref`
--> $DIR/issue-51244.rs:13:5
|
LL | let ref my_ref @ _ = 0;
| -------------- consider changing this to `ref mut my_ref @ _`
| --- consider changing this to `ref mut`
LL | *my_ref = 0;
| ^^^^^^^^^^^ cannot borrow as mutable