]> git.lizzy.rs Git - rust.git/commitdiff
Fix issue #51515 and update test
authorashtneoi <ashtneoi@gmail.com>
Mon, 9 Jul 2018 20:33:57 +0000 (13:33 -0700)
committerashtneoi <ashtneoi@gmail.com>
Mon, 9 Jul 2018 20:33:57 +0000 (13:33 -0700)
src/librustc_mir/borrow_check/mod.rs
src/test/ui/suggestions/issue-51515.rs
src/test/ui/suggestions/issue-51515.stderr

index a5db0d15d8ab309414ab7c3de44c8ea9fa785e0b..1a66a2d2cb902a0614f0e5c2b45ad3c227d0755b 100644 (file)
@@ -1905,8 +1905,10 @@ fn find_place_to_suggest_ampmut<'cx, 'gcx, 'tcx>(
                     // highlighted text will always be `&<expr>` and
                     // thus can transform to `&mut` by slicing off
                     // first ASCII character and prepending "&mut ".
-                    let borrowed_expr = src[1..].to_string();
-                    return (assignment_rhs_span, format!("&mut {}", borrowed_expr));
+                    if src.starts_with('&') {
+                        let borrowed_expr = src[1..].to_string();
+                        return (assignment_rhs_span, format!("&mut {}", borrowed_expr));
+                    }
                 }
             }
 
index b5bbf48ddfac84aea2e8f18f431edc276c87868b..3e0a3b757a3d68a73d93a6acc322233a05e88617 100644 (file)
 
 fn main() {
     let foo = &16;
+    //~^ HELP consider changing this to be a mutable reference
+    //~| SUGGESTION &mut 16
     *foo = 32;
+    //~^ ERROR cannot assign to `*foo` which is behind a `&` reference
     let bar = foo;
+    //~^ HELP consider changing this to be a mutable reference
+    //~| SUGGESTION &mut i32
     *bar = 64;
+    //~^ ERROR cannot assign to `*bar` which is behind a `&` reference
 }
index 7cdbef1badc7646b724e8a94b6eea3c042b49cbb..3e7349b5acabf095e14f43dabd7669ec3f2caac9 100644 (file)
@@ -1,14 +1,18 @@
 error[E0594]: cannot assign to `*foo` which is behind a `&` reference
-  --> $DIR/issue-51515.rs:15:5
+  --> $DIR/issue-51515.rs:17:5
    |
 LL |     let foo = &16;
    |               --- help: consider changing this to be a mutable reference: `&mut 16`
+...
 LL |     *foo = 32;
    |     ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written
 
 error[E0594]: cannot assign to `*bar` which is behind a `&` reference
-  --> $DIR/issue-51515.rs:17:5
+  --> $DIR/issue-51515.rs:22:5
    |
+LL |     let bar = foo;
+   |         --- help: consider changing this to be a mutable reference: `&mut i32`
+...
 LL |     *bar = 64;
    |     ^^^^^^^^^ `bar` is a `&` reference, so the data it refers to cannot be written