Skip to content

Commit 78e1b3d

Browse files
committed
lint with ref_span
1 parent 9d42c80 commit 78e1b3d

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/librustc_borrowck/borrowck/mod.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1196,14 +1196,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
11961196
let let_span = self.tcx.hir.span(node_id);
11971197
match self.local_binding_mode(node_id) {
11981198
ty::BindByReference(..) => {
1199-
let snippet = self.tcx.sess.codemap().span_to_snippet(let_span);
1200-
if let Ok(snippet) = snippet {
1199+
let ref_span = self.tcx.sess.codemap().span_until_whitespace(let_span);
1200+
if let Ok(_) = self.tcx.sess.codemap().span_to_snippet(let_span) {
12011201
db.span_label(
1202-
let_span,
1203-
format!("consider changing this to `{}`",
1204-
snippet.replacen("ref ", "ref mut ", 1))
1205-
);
1206-
}
1202+
ref_span,
1203+
format!("consider changing this to `{}`", "ref mut"));
1204+
};
12071205
}
12081206
ty::BindByValue(..) => {
12091207
if let (Some(local_ty), is_implicit_self) = self.local_ty(node_id) {

src/test/ui/suggestions/issue-51244.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0594]: cannot assign to immutable borrowed content `*my_ref`
22
--> $DIR/issue-51244.rs:13:5
33
|
44
LL | let ref my_ref @ _ = 0;
5-
| -------------- consider changing this to `ref mut my_ref @ _`
5+
| --- consider changing this to `ref mut`
66
LL | *my_ref = 0;
77
| ^^^^^^^^^^^ cannot borrow as mutable
88

0 commit comments

Comments
 (0)