Skip to content

Commit 1662daa

Browse files
csmoeashtneoi
authored andcommitted
lint with ref_span
1 parent 4e5d228 commit 1662daa

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
@@ -1209,14 +1209,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
12091209
let let_span = self.tcx.hir.span(node_id);
12101210
match self.local_binding_mode(node_id) {
12111211
ty::BindByReference(..) => {
1212-
let snippet = self.tcx.sess.codemap().span_to_snippet(let_span);
1213-
if let Ok(snippet) = snippet {
1212+
let ref_span = self.tcx.sess.codemap().span_until_whitespace(let_span);
1213+
if let Ok(_) = self.tcx.sess.codemap().span_to_snippet(let_span) {
12141214
db.span_label(
1215-
let_span,
1216-
format!("consider changing this to `{}`",
1217-
snippet.replacen("ref ", "ref mut ", 1))
1218-
);
1219-
}
1215+
ref_span,
1216+
format!("consider changing this to `{}`", "ref mut"));
1217+
};
12201218
}
12211219
ty::BindByValue(..) => {
12221220
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)