about summary refs log tree commit diff
diff options
context:
space:
mode:
authorcsmoe <35686186+csmoe@users.noreply.github.com>2018-06-01 19:00:15 +0800
committerashtneoi <ashtneoi@gmail.com>2018-07-12 22:51:30 -0700
commitaf5edc32df6a30bc7c8caa01bb9700b38354e21f (patch)
tree6769968ec2b0b6a6e145b5e2237f7499472e8757
parent1662daa23d77d77107743926efee72e8254d8f35 (diff)
downloadrust-af5edc32df6a30bc7c8caa01bb9700b38354e21f.tar.gz
rust-af5edc32df6a30bc7c8caa01bb9700b38354e21f.zip
replace ref
-rw-r--r--src/librustc_borrowck/borrowck/mod.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs
index f09feac51fc..aa00ccd1f08 100644
--- a/src/librustc_borrowck/borrowck/mod.rs
+++ b/src/librustc_borrowck/borrowck/mod.rs
@@ -1209,11 +1209,16 @@ 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 ref_span = self.tcx.sess.codemap().span_until_whitespace(let_span);
-                        if let Ok(_) = self.tcx.sess.codemap().span_to_snippet(let_span) {
+                        if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(let_span) {
+                            let replace_str = if snippet.starts_with("ref ") {
+                                snippet.replacen("ref ", "ref mut ", 1)
+                            } else {
+                                snippet
+                            };
                             db.span_label(
-                                ref_span,
-                                format!("consider changing this to `{}`", "ref mut"));
+                                let_span,
+                                format!("consider changing this to `{}`", replace_str)
+                            );
                         };
                     }
                     ty::BindByValue(..) => {