Skip to content

Commit af5edc3

Browse files
csmoeashtneoi
authored andcommitted
replace ref
1 parent 1662daa commit af5edc3

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
@@ -1209,11 +1209,16 @@ 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 ref_span = self.tcx.sess.codemap().span_until_whitespace(let_span);
1213-
if let Ok(_) = self.tcx.sess.codemap().span_to_snippet(let_span) {
1212+
if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(let_span) {
1213+
let replace_str = if snippet.starts_with("ref ") {
1214+
snippet.replacen("ref ", "ref mut ", 1)
1215+
} else {
1216+
snippet
1217+
};
12141218
db.span_label(
1215-
ref_span,
1216-
format!("consider changing this to `{}`", "ref mut"));
1219+
let_span,
1220+
format!("consider changing this to `{}`", replace_str)
1221+
);
12171222
};
12181223
}
12191224
ty::BindByValue(..) => {

0 commit comments

Comments
 (0)