]> git.lizzy.rs Git - rust.git/blobdiff - src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.rs
--bless bindings-after-at tests
[rust.git] / src / test / ui / pattern / bindings-after-at / borrowck-pat-ref-mut-and-ref.rs
index 3ea3d93f862f57be787856a0775cfe0eec3a0238..35dddfdbb1fbb22cc89419b2b6def23ff927bc01 100644 (file)
@@ -9,7 +9,8 @@ enum Option<T> {
 fn main() {
     match &mut Some(1) {
         ref mut z @ &mut Some(ref a) => {
-        //~^ ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
+        //~^ ERROR cannot borrow `z` as immutable because it is also borrowed as mutable
+        //~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
             **z = None;
             println!("{}", *a);
         }
@@ -18,30 +19,38 @@ fn main() {
 
     struct U;
 
-    let ref a @ ref mut b = U; // FIXME: This should not compile.
-    let ref mut a @ ref b = U; // FIXME: This should not compile.
-    let ref a @ (ref mut b, ref mut c) = (U, U); // FIXME: This should not compile.
-    let ref mut a @ (ref b, ref c) = (U, U); // FIXME: This should not compile.
+    let ref a @ ref mut b = U;
+    //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
+    let ref mut a @ ref b = U;
+    //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
+    let ref a @ (ref mut b, ref mut c) = (U, U);
+    //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
+    let ref mut a @ (ref b, ref c) = (U, U);
+    //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
 
-    // FIXME: Seems like we have a soundness hole here.
     let ref mut a @ ref b = U;
-    *a = U; // We are mutating...
-    drop(b); // ..but at the same time we are holding a live shared borrow.
-    // FIXME: Inverted; seems like the same issue exists here as well.
+    //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
+    *a = U;
+    drop(b);
     let ref a @ ref mut b = U;
+    //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
     *b = U;
     drop(a);
 
     match Ok(U) {
         ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) => {
-            *a = Err(U); // FIXME: ^ should not compile.
+            //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
+            //~| ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
+            *a = Err(U);
             drop(b);
         }
     }
 
     match Ok(U) {
         ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
-            //~^ ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
+            //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
+            //~| ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
+            //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
             //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
             *b = U;
             drop(a);
@@ -50,38 +59,50 @@ fn main() {
 
     match Ok(U) {
         ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false } => {}
-        //~^ ERROR cannot assign to `*b`, as it is immutable for the pattern guard
+        //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
+        //~| ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
+        //~| ERROR cannot assign to `*b`, as it is immutable for the pattern guard
         _ => {}
     }
     match Ok(U) {
         ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { *a = Err(U); false } => {}
-        //~^ ERROR cannot assign to `*a`, as it is immutable for the pattern guard
+        //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
+        //~| ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
+        //~| ERROR cannot assign to `*a`, as it is immutable for the pattern guard
         _ => {}
     }
     match Ok(U) {
         ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false } => {}
-        //~^ ERROR cannot move out of `b` in pattern guard
+        //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
+        //~| ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
+        //~| ERROR cannot move out of `b` in pattern guard
         _ => {}
     }
     match Ok(U) {
         ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false } => {}
-        //~^ ERROR cannot move out of `a` in pattern guard
+        //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
+        //~| ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
+        //~| ERROR cannot move out of `a` in pattern guard
         _ => {}
     }
 
     let ref a @ (ref mut b, ref mut c) = (U, U);
-    *b = U; // FIXME: ^ should not compile.
+    //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
+    *b = U;
     *c = U;
 
     let ref a @ (ref mut b, ref mut c) = (U, U);
-    //~^ ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
+    //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
+    //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
     //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
     *b = U;
     drop(a);
 
     let ref a @ (ref mut b, ref mut c) = (U, U);
-    *b = U; //~^ ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
+    //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
+    *b = U; //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
     *c = U; //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
     drop(a);
-    let ref mut a @ (ref b, ref c) = (U, U); // FIXME: This should not compile.
+    let ref mut a @ (ref b, ref c) = (U, U);
+    //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
 }