Skip to content

Commit 62c4544

Browse files
committed
replace ref
1 parent 78e1b3d commit 62c4544

File tree

1 file changed

+9
-4
lines changed
  • src/librustc_borrowck/borrowck

1 file changed

+9
-4
lines changed

src/librustc_borrowck/borrowck/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1196,11 +1196,16 @@ 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 ref_span = self.tcx.sess.codemap().span_until_whitespace(let_span);
1200-
if let Ok(_) = self.tcx.sess.codemap().span_to_snippet(let_span) {
1199+
if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(let_span) {
1200+
let replace_str = if snippet.starts_with("ref ") {
1201+
snippet.replacen("ref ", "ref mut ", 1)
1202+
} else {
1203+
snippet
1204+
};
12011205
db.span_label(
1202-
ref_span,
1203-
format!("consider changing this to `{}`", "ref mut"));
1206+
let_span,
1207+
format!("consider changing this to `{}`", replace_str)
1208+
);
12041209
};
12051210
}
12061211
ty::BindByValue(..) => {

0 commit comments

Comments
 (0)