]> git.lizzy.rs Git - rust.git/commitdiff
--bless bindings-after-at tests
authorMazdak Farrokhzad <twingoow@gmail.com>
Sat, 14 Dec 2019 23:32:20 +0000 (00:32 +0100)
committerMazdak Farrokhzad <twingoow@gmail.com>
Mon, 23 Dec 2019 13:47:19 +0000 (14:47 +0100)
src/librustc_mir/hair/pattern/check_match.rs
src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.rs
src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.stderr
src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.rs
src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.stderr
src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-twice.rs
src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-twice.stderr

index 8abe3508fd681215806ce8af81e451b601a5f86b..67c89c7293c43d1698ea9982a2a672476b0d9478 100644 (file)
@@ -695,7 +695,7 @@ fn check_borrow_conflicts_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat) {
             };
             let msg = &format!(
                 "cannot borrow `{}` as {} because it is also borrowed as {}",
-                name, primary, also,
+                name, also, primary,
             );
             let mut err = sess.struct_span_err(pat.span, msg);
             err.span_label(binding_span, &format!("{} borrow occurs here", primary));
index 4d94d94ae0e184007aed3d2150253602b05aabf9..7a4fe96b21330616ea1fea9dd768f619d4b9e337 100644 (file)
@@ -29,16 +29,20 @@ fn main() {
     drop(a);
     drop(b);
 
-    let ref a @ box ref mut b = Box::new(NC); // FIXME: This should not compile.
-    let ref a @ box ref mut b = Box::new(NC); // FIXME: This should not compile.
+    let ref a @ box ref mut b = Box::new(NC);
+    //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
+    let ref a @ box ref mut b = Box::new(NC);
+    //~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
     *b = NC;
     let ref a @ box ref mut b = Box::new(NC);
-    //~^ 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
     *b = NC;
     drop(a);
 
     let ref mut a @ box ref b = Box::new(NC);
-    //~^ ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
+    //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
+    //~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
     *a = Box::new(NC);
     drop(b);
 }
index af0bcb69bbbeace1d6c9ae980471d74b033e0c17..7bb2379968e5d6f5a4dedf697866b96a8ebed9bb 100644 (file)
@@ -27,6 +27,42 @@ LL |     let ref a @ box b = Box::new(NC);
    |         |           by-move pattern here
    |         by-ref pattern here
 
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+  --> $DIR/borrowck-pat-at-and-box.rs:32:9
+   |
+LL |     let ref a @ box ref mut b = Box::new(NC);
+   |         -----^^^^^^^---------
+   |         |           |
+   |         |           mutable borrow occurs here
+   |         immutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+  --> $DIR/borrowck-pat-at-and-box.rs:34:9
+   |
+LL |     let ref a @ box ref mut b = Box::new(NC);
+   |         -----^^^^^^^---------
+   |         |           |
+   |         |           mutable borrow occurs here
+   |         immutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+  --> $DIR/borrowck-pat-at-and-box.rs:37:9
+   |
+LL |     let ref a @ box ref mut b = Box::new(NC);
+   |         -----^^^^^^^---------
+   |         |           |
+   |         |           mutable borrow occurs here
+   |         immutable borrow occurs here
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+  --> $DIR/borrowck-pat-at-and-box.rs:43:9
+   |
+LL |     let ref mut a @ box ref b = Box::new(NC);
+   |         ---------^^^^^^^-----
+   |         |               |
+   |         |               immutable borrow occurs here
+   |         mutable borrow occurs here
+
 error[E0382]: use of moved value
   --> $DIR/borrowck-pat-at-and-box.rs:11:18
    |
@@ -46,7 +82,7 @@ LL |     let a @ box b = Box::new(C);
    |         value moved here
 
 error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
-  --> $DIR/borrowck-pat-at-and-box.rs:35:21
+  --> $DIR/borrowck-pat-at-and-box.rs:37:21
    |
 LL |     let ref a @ box ref mut b = Box::new(NC);
    |         ------------^^^^^^^^^
@@ -58,18 +94,18 @@ LL |     drop(a);
    |          - immutable borrow later used here
 
 error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable
-  --> $DIR/borrowck-pat-at-and-box.rs:40:25
+  --> $DIR/borrowck-pat-at-and-box.rs:43:25
    |
 LL |     let ref mut a @ box ref b = Box::new(NC);
    |         ----------------^^^^^
    |         |               |
    |         |               immutable borrow occurs here
    |         mutable borrow occurs here
-LL |
+...
 LL |     *a = Box::new(NC);
    |     -- mutable borrow later used here
 
-error: aborting due to 7 previous errors
+error: aborting due to 11 previous errors
 
 Some errors have detailed explanations: E0007, E0009, E0382, E0502.
 For more information about an error, try `rustc --explain E0007`.
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
 }
index 27b94e055a0a4fdb24199f1726bd09785e9a446e..7059f3c7caa8c627e82e42cd24055662703bb5da 100644 (file)
@@ -6,6 +6,219 @@ LL | #![feature(bindings_after_at)]
    |
    = note: `#[warn(incomplete_features)]` on by default
 
+error: cannot borrow `z` as immutable because it is also borrowed as mutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:11:9
+   |
+LL |         ref mut z @ &mut Some(ref a) => {
+   |         ---------^^^^^^^^^^^^^-----^
+   |         |                     |
+   |         |                     immutable borrow occurs here
+   |         mutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:22:9
+   |
+LL |     let ref a @ ref mut b = U;
+   |         -----^^^---------
+   |         |       |
+   |         |       mutable borrow occurs here
+   |         immutable borrow occurs here
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:24:9
+   |
+LL |     let ref mut a @ ref b = U;
+   |         ---------^^^-----
+   |         |           |
+   |         |           immutable borrow occurs here
+   |         mutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:26:9
+   |
+LL |     let ref a @ (ref mut b, ref mut c) = (U, U);
+   |         -----^^^^---------^^---------^
+   |         |        |          |
+   |         |        |          mutable borrow occurs here
+   |         |        mutable borrow occurs here
+   |         immutable borrow occurs here
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:28:9
+   |
+LL |     let ref mut a @ (ref b, ref c) = (U, U);
+   |         ---------^^^^-----^^-----^
+   |         |            |      |
+   |         |            |      immutable borrow occurs here
+   |         |            immutable borrow occurs here
+   |         mutable borrow occurs here
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:31:9
+   |
+LL |     let ref mut a @ ref b = U;
+   |         ---------^^^-----
+   |         |           |
+   |         |           immutable borrow occurs here
+   |         mutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:35:9
+   |
+LL |     let ref a @ ref mut b = U;
+   |         -----^^^---------
+   |         |       |
+   |         |       mutable borrow occurs here
+   |         immutable borrow occurs here
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:41:9
+   |
+LL |         ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) => {
+   |         ---------^^^^^^-----^
+   |         |              |
+   |         |              immutable borrow occurs here
+   |         mutable borrow occurs here
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:41:33
+   |
+LL |         ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) => {
+   |                                 ---------^^^^^^^-----^
+   |                                 |               |
+   |                                 |               immutable borrow occurs here
+   |                                 mutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:50:9
+   |
+LL |         ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
+   |         -----^^^^^^---------^
+   |         |          |
+   |         |          mutable borrow occurs here
+   |         immutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:50:33
+   |
+LL |         ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
+   |                                 -----^^^^^^^---------^
+   |                                 |           |
+   |                                 |           mutable borrow occurs here
+   |                                 immutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:61:9
+   |
+LL |         ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false } => {}
+   |         -----^^^^^^---------^
+   |         |          |
+   |         |          mutable borrow occurs here
+   |         immutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:61:33
+   |
+LL |         ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false } => {}
+   |                                 -----^^^^^^^---------^
+   |                                 |           |
+   |                                 |           mutable borrow occurs here
+   |                                 immutable borrow occurs here
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:68:9
+   |
+LL |         ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { *a = Err(U); false } => {}
+   |         ---------^^^^^^-----^
+   |         |              |
+   |         |              immutable borrow occurs here
+   |         mutable borrow occurs here
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:68:33
+   |
+LL |         ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { *a = Err(U); false } => {}
+   |                                 ---------^^^^^^^-----^
+   |                                 |               |
+   |                                 |               immutable borrow occurs here
+   |                                 mutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:75:9
+   |
+LL |         ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false } => {}
+   |         -----^^^^^^---------^
+   |         |          |
+   |         |          mutable borrow occurs here
+   |         immutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:75:33
+   |
+LL |         ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false } => {}
+   |                                 -----^^^^^^^---------^
+   |                                 |           |
+   |                                 |           mutable borrow occurs here
+   |                                 immutable borrow occurs here
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:82:9
+   |
+LL |         ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false } => {}
+   |         ---------^^^^^^-----^
+   |         |              |
+   |         |              immutable borrow occurs here
+   |         mutable borrow occurs here
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:82:33
+   |
+LL |         ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false } => {}
+   |                                 ---------^^^^^^^-----^
+   |                                 |               |
+   |                                 |               immutable borrow occurs here
+   |                                 mutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:89:9
+   |
+LL |     let ref a @ (ref mut b, ref mut c) = (U, U);
+   |         -----^^^^---------^^---------^
+   |         |        |          |
+   |         |        |          mutable borrow occurs here
+   |         |        mutable borrow occurs here
+   |         immutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:94:9
+   |
+LL |     let ref a @ (ref mut b, ref mut c) = (U, U);
+   |         -----^^^^---------^^---------^
+   |         |        |          |
+   |         |        |          mutable borrow occurs here
+   |         |        mutable borrow occurs here
+   |         immutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:101:9
+   |
+LL |     let ref a @ (ref mut b, ref mut c) = (U, U);
+   |         -----^^^^---------^^---------^
+   |         |        |          |
+   |         |        |          mutable borrow occurs here
+   |         |        mutable borrow occurs here
+   |         immutable borrow occurs here
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:106:9
+   |
+LL |     let ref mut a @ (ref b, ref c) = (U, U);
+   |         ---------^^^^-----^^-----^
+   |         |            |      |
+   |         |            |      immutable borrow occurs here
+   |         |            immutable borrow occurs here
+   |         mutable borrow occurs here
+
 error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable
   --> $DIR/borrowck-pat-ref-mut-and-ref.rs:11:31
    |
@@ -14,12 +227,12 @@ LL |         ref mut z @ &mut Some(ref a) => {
    |         |                     |
    |         |                     immutable borrow occurs here
    |         mutable borrow occurs here
-LL |
+...
 LL |             **z = None;
    |             ---------- mutable borrow later used here
 
 error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
-  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:43:20
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:50:20
    |
 LL |         ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
    |         -----------^^^^^^^^^-
@@ -31,7 +244,7 @@ LL |             drop(a);
    |                  - immutable borrow later used here
 
 error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
-  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:43:45
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:50:45
    |
 LL |         ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
    |                                 ------------^^^^^^^^^-
@@ -43,7 +256,7 @@ LL |             drop(a);
    |                  - immutable borrow later used here
 
 error[E0594]: cannot assign to `*b`, as it is immutable for the pattern guard
-  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:52:61
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:61:61
    |
 LL |         ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false } => {}
    |                                                             ^^^^^^ cannot assign
@@ -51,7 +264,7 @@ LL |         ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false }
    = note: variables bound in patterns are immutable until the end of the pattern guard
 
 error[E0594]: cannot assign to `*a`, as it is immutable for the pattern guard
-  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:57:61
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:68:61
    |
 LL |         ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { *a = Err(U); false } => {}
    |                                                             ^^^^^^^^^^^ cannot assign
@@ -59,7 +272,7 @@ LL |         ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { *a = Err(U); fa
    = note: variables bound in patterns are immutable until the end of the pattern guard
 
 error[E0507]: cannot move out of `b` in pattern guard
-  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:62:66
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:75:66
    |
 LL |         ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false } => {}
    |                                                                  ^ move occurs because `b` has type `&mut main::U`, which does not implement the `Copy` trait
@@ -67,7 +280,7 @@ LL |         ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false
    = note: variables bound in patterns cannot be moved from until after the end of the pattern guard
 
 error[E0507]: cannot move out of `a` in pattern guard
-  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:67:66
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:82:66
    |
 LL |         ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false } => {}
    |                                                                  ^ move occurs because `a` has type `&mut std::result::Result<main::U, main::U>`, which does not implement the `Copy` trait
@@ -75,7 +288,7 @@ LL |         ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false
    = note: variables bound in patterns cannot be moved from until after the end of the pattern guard
 
 error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
-  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:76:18
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:94:18
    |
 LL |     let ref a @ (ref mut b, ref mut c) = (U, U);
    |         ---------^^^^^^^^^------------
@@ -87,7 +300,7 @@ LL |     drop(a);
    |          - immutable borrow later used here
 
 error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
-  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:76:29
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:94:29
    |
 LL |     let ref a @ (ref mut b, ref mut c) = (U, U);
    |         --------------------^^^^^^^^^-
@@ -99,7 +312,7 @@ LL |     drop(a);
    |          - immutable borrow later used here
 
 error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
-  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:82:18
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:101:18
    |
 LL |     let ref a @ (ref mut b, ref mut c) = (U, U);
    |         ---------^^^^^^^^^------------
@@ -111,7 +324,7 @@ LL |     drop(a);
    |          - immutable borrow later used here
 
 error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
-  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:82:29
+  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:101:29
    |
 LL |     let ref a @ (ref mut b, ref mut c) = (U, U);
    |         --------------------^^^^^^^^^-
@@ -122,7 +335,7 @@ LL |     let ref a @ (ref mut b, ref mut c) = (U, U);
 LL |     drop(a);
    |          - immutable borrow later used here
 
-error: aborting due to 11 previous errors
+error: aborting due to 34 previous errors
 
 Some errors have detailed explanations: E0502, E0507, E0594.
 For more information about an error, try `rustc --explain E0502`.
index 482fa0497f5716506140f22f31bfc1051236a15f..f76d9ce73cf258c4fc2935d0a68d2ad9da905634 100644 (file)
@@ -7,20 +7,32 @@ fn main() {
     struct U;
 
     let ref mut a @ ref mut b = U;
-    //~^ ERROR cannot borrow `_` as mutable more than once at a time
+    //~^ ERROR cannot borrow `a` as mutable more than once at a time
+    //~| ERROR cannot borrow `_` as mutable more than once at a time
     drop(a);
-    let ref mut a @ ref mut b = U; // FIXME: This should not compile.
+    let ref mut a @ ref mut b = U;
+    //~^ ERROR cannot borrow `a` as mutable more than once at a time
     drop(b);
-    let ref mut a @ ref mut b = U; // FIXME: This should not compile.
+    let ref mut a @ ref mut b = U;
+    //~^ ERROR cannot borrow `a` as mutable more than once at a time
 
     let ref mut a @ ref mut b = U;
-    //~^ ERROR cannot borrow `_` as mutable more than once at a time
+    //~^ ERROR cannot borrow `a` as mutable more than once at a time
+    //~| ERROR cannot borrow `_` as mutable more than once at a time
     *a = U;
-    let ref mut a @ ref mut b = U; // FIXME: This should not compile.
+    let ref mut a @ ref mut b = U;
+    //~^ ERROR cannot borrow `a` as mutable more than once at a time
     *b = U;
 
-    let ref mut a @ (ref mut b, [ref mut c, ref mut d]) = (U, [U, U]);
-    // FIXME: This should not compile.
+    let ref mut a @ (
+    //~^ ERROR cannot borrow `a` as mutable more than once at a time
+        ref mut b,
+        [
+            ref mut c,
+            ref mut d,
+            ref e,
+        ]
+    ) = (U, [U, U, U]);
 
     let a @ (ref mut b, ref mut c) = (U, U);
     //~^ ERROR cannot bind by-move with sub-bindings
@@ -39,18 +51,22 @@ fn main() {
 
     match Ok(U) {
         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
-            // FIXME: This should not compile.
+            //~^ ERROR cannot borrow `a` as mutable more than once at a time
+            //~| ERROR cannot borrow `a` as mutable more than once at a time
         }
     }
     match Ok(U) {
         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
+            //~^ ERROR cannot borrow `a` as mutable more than once at a time
+            //~| ERROR cannot borrow `a` as mutable more than once at a time
             *b = U;
-            // FIXME: This should not compile.
         }
     }
     match Ok(U) {
         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
-            //~^ ERROR cannot borrow `_` as mutable more than once at a time
+            //~^ ERROR cannot borrow `a` as mutable more than once at a time
+            //~| ERROR cannot borrow `a` as mutable more than once at a time
+            //~| ERROR cannot borrow `_` as mutable more than once at a time
             //~| ERROR cannot borrow `_` as mutable more than once at a time
             *a = Err(U);
 
@@ -60,7 +76,9 @@ fn main() {
     }
     match Ok(U) {
         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
-            //~^ ERROR cannot borrow `_` as mutable more than once at a time
+            //~^ ERROR cannot borrow `a` as mutable more than once at a time
+            //~| ERROR cannot borrow `a` as mutable more than once at a time
+            //~| ERROR cannot borrow `_` as mutable more than once at a time
             //~| ERROR cannot borrow `_` as mutable more than once at a time
             drop(a);
         }
index c9bfba867787e673b237e3a8c67f4064359b50c3..e8176342a0c458184a2170d16681cd269b226077 100644 (file)
@@ -6,30 +6,169 @@ LL | #![feature(bindings_after_at)]
    |
    = note: `#[warn(incomplete_features)]` on by default
 
+error: cannot borrow `a` as mutable more than once at a time
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:9:9
+   |
+LL |     let ref mut a @ ref mut b = U;
+   |         ---------^^^---------
+   |         |           |
+   |         |           another mutable borrow occurs here
+   |         first mutable borrow occurs here
+
+error: cannot borrow `a` as mutable more than once at a time
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:13:9
+   |
+LL |     let ref mut a @ ref mut b = U;
+   |         ---------^^^---------
+   |         |           |
+   |         |           another mutable borrow occurs here
+   |         first mutable borrow occurs here
+
+error: cannot borrow `a` as mutable more than once at a time
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:16:9
+   |
+LL |     let ref mut a @ ref mut b = U;
+   |         ---------^^^---------
+   |         |           |
+   |         |           another mutable borrow occurs here
+   |         first mutable borrow occurs here
+
+error: cannot borrow `a` as mutable more than once at a time
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:19:9
+   |
+LL |     let ref mut a @ ref mut b = U;
+   |         ---------^^^---------
+   |         |           |
+   |         |           another mutable borrow occurs here
+   |         first mutable borrow occurs here
+
+error: cannot borrow `a` as mutable more than once at a time
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:23:9
+   |
+LL |     let ref mut a @ ref mut b = U;
+   |         ---------^^^---------
+   |         |           |
+   |         |           another mutable borrow occurs here
+   |         first mutable borrow occurs here
+
+error: cannot borrow `a` as mutable more than once at a time
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:27:9
+   |
+LL |       let ref mut a @ (
+   |           ^--------
+   |           |
+   |  _________first mutable borrow occurs here
+   | |
+LL | |
+LL | |         ref mut b,
+   | |         --------- another mutable borrow occurs here
+LL | |         [
+LL | |             ref mut c,
+   | |             --------- another mutable borrow occurs here
+LL | |             ref mut d,
+   | |             --------- another mutable borrow occurs here
+LL | |             ref e,
+   | |             ----- also borrowed as immutable here
+LL | |         ]
+LL | |     ) = (U, [U, U, U]);
+   | |_____^
+
 error[E0007]: cannot bind by-move with sub-bindings
-  --> $DIR/borrowck-pat-ref-mut-twice.rs:25:9
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:37:9
    |
 LL |     let a @ (ref mut b, ref mut c) = (U, U);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
 
 error[E0007]: cannot bind by-move with sub-bindings
-  --> $DIR/borrowck-pat-ref-mut-twice.rs:29:9
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:41:9
    |
 LL |     let a @ (b, [c, d]) = &mut val; // Same as ^--
    |         ^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
 
 error[E0007]: cannot bind by-move with sub-bindings
-  --> $DIR/borrowck-pat-ref-mut-twice.rs:33:9
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:45:9
    |
 LL |     let a @ &mut ref mut b = &mut U;
    |         ^^^^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
 
 error[E0007]: cannot bind by-move with sub-bindings
-  --> $DIR/borrowck-pat-ref-mut-twice.rs:36:9
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:48:9
    |
 LL |     let a @ &mut (ref mut b, ref mut c) = &mut (U, U);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
 
+error: cannot borrow `a` as mutable more than once at a time
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:53:9
+   |
+LL |         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
+   |         ---------^^^^^^---------^
+   |         |              |
+   |         |              another mutable borrow occurs here
+   |         first mutable borrow occurs here
+
+error: cannot borrow `a` as mutable more than once at a time
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:53:37
+   |
+LL |         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
+   |                                     ---------^^^^^^^---------^
+   |                                     |               |
+   |                                     |               another mutable borrow occurs here
+   |                                     first mutable borrow occurs here
+
+error: cannot borrow `a` as mutable more than once at a time
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:59:9
+   |
+LL |         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
+   |         ---------^^^^^^---------^
+   |         |              |
+   |         |              another mutable borrow occurs here
+   |         first mutable borrow occurs here
+
+error: cannot borrow `a` as mutable more than once at a time
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:59:37
+   |
+LL |         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
+   |                                     ---------^^^^^^^---------^
+   |                                     |               |
+   |                                     |               another mutable borrow occurs here
+   |                                     first mutable borrow occurs here
+
+error: cannot borrow `a` as mutable more than once at a time
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:66:9
+   |
+LL |         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
+   |         ---------^^^^^^---------^
+   |         |              |
+   |         |              another mutable borrow occurs here
+   |         first mutable borrow occurs here
+
+error: cannot borrow `a` as mutable more than once at a time
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:66:37
+   |
+LL |         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
+   |                                     ---------^^^^^^^---------^
+   |                                     |               |
+   |                                     |               another mutable borrow occurs here
+   |                                     first mutable borrow occurs here
+
+error: cannot borrow `a` as mutable more than once at a time
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:78:9
+   |
+LL |         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
+   |         ---------^^^^^^---------^
+   |         |              |
+   |         |              another mutable borrow occurs here
+   |         first mutable borrow occurs here
+
+error: cannot borrow `a` as mutable more than once at a time
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:78:37
+   |
+LL |         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
+   |                                     ---------^^^^^^^---------^
+   |                                     |               |
+   |                                     |               another mutable borrow occurs here
+   |                                     first mutable borrow occurs here
+
 error[E0499]: cannot borrow `_` as mutable more than once at a time
   --> $DIR/borrowck-pat-ref-mut-twice.rs:9:21
    |
@@ -38,24 +177,24 @@ LL |     let ref mut a @ ref mut b = U;
    |         |           |
    |         |           second mutable borrow occurs here
    |         first mutable borrow occurs here
-LL |
+...
 LL |     drop(a);
    |          - first borrow later used here
 
 error[E0499]: cannot borrow `_` as mutable more than once at a time
-  --> $DIR/borrowck-pat-ref-mut-twice.rs:16:21
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:19:21
    |
 LL |     let ref mut a @ ref mut b = U;
    |         ------------^^^^^^^^^
    |         |           |
    |         |           second mutable borrow occurs here
    |         first mutable borrow occurs here
-LL |
+...
 LL |     *a = U;
    |     ------ first borrow later used here
 
 error[E0382]: borrow of moved value
-  --> $DIR/borrowck-pat-ref-mut-twice.rs:25:25
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:37:25
    |
 LL |     let a @ (ref mut b, ref mut c) = (U, U);
    |         ----------------^^^^^^^^^-   ------ move occurs because value has type `(main::U, main::U)`, which does not implement the `Copy` trait
@@ -64,7 +203,7 @@ LL |     let a @ (ref mut b, ref mut c) = (U, U);
    |         value moved here
 
 error[E0382]: borrow of moved value
-  --> $DIR/borrowck-pat-ref-mut-twice.rs:29:21
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:41:21
    |
 LL |     let a @ (b, [c, d]) = &mut val; // Same as ^--
    |         ------------^--   -------- move occurs because value has type `&mut (main::U, [main::U; 2])`, which does not implement the `Copy` trait
@@ -73,7 +212,7 @@ LL |     let a @ (b, [c, d]) = &mut val; // Same as ^--
    |         value moved here
 
 error[E0382]: borrow of moved value
-  --> $DIR/borrowck-pat-ref-mut-twice.rs:33:18
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:45:18
    |
 LL |     let a @ &mut ref mut b = &mut U;
    |         ---------^^^^^^^^^   ------ move occurs because value has type `&mut main::U`, which does not implement the `Copy` trait
@@ -82,7 +221,7 @@ LL |     let a @ &mut ref mut b = &mut U;
    |         value moved here
 
 error[E0382]: borrow of moved value
-  --> $DIR/borrowck-pat-ref-mut-twice.rs:36:30
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:48:30
    |
 LL |     let a @ &mut (ref mut b, ref mut c) = &mut (U, U);
    |         ---------------------^^^^^^^^^-   ----------- move occurs because value has type `&mut (main::U, main::U)`, which does not implement the `Copy` trait
@@ -91,7 +230,7 @@ LL |     let a @ &mut (ref mut b, ref mut c) = &mut (U, U);
    |         value moved here
 
 error[E0499]: cannot borrow `_` as mutable more than once at a time
-  --> $DIR/borrowck-pat-ref-mut-twice.rs:52:24
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:66:24
    |
 LL |         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
    |         ---------------^^^^^^^^^-
@@ -103,7 +242,7 @@ LL |             *a = Err(U);
    |             ----------- first borrow later used here
 
 error[E0499]: cannot borrow `_` as mutable more than once at a time
-  --> $DIR/borrowck-pat-ref-mut-twice.rs:52:53
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:66:53
    |
 LL |         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
    |                                     ----------------^^^^^^^^^-
@@ -115,7 +254,7 @@ LL |             *a = Err(U);
    |             ----------- first borrow later used here
 
 error[E0499]: cannot borrow `_` as mutable more than once at a time
-  --> $DIR/borrowck-pat-ref-mut-twice.rs:62:24
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:78:24
    |
 LL |         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
    |         ---------------^^^^^^^^^-
@@ -127,7 +266,7 @@ LL |             drop(a);
    |                  - first borrow later used here
 
 error[E0499]: cannot borrow `_` as mutable more than once at a time
-  --> $DIR/borrowck-pat-ref-mut-twice.rs:62:53
+  --> $DIR/borrowck-pat-ref-mut-twice.rs:78:53
    |
 LL |         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
    |                                     ----------------^^^^^^^^^-
@@ -138,7 +277,7 @@ LL |         ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
 LL |             drop(a);
    |                  - first borrow later used here
 
-error: aborting due to 14 previous errors
+error: aborting due to 28 previous errors
 
 Some errors have detailed explanations: E0007, E0382, E0499.
 For more information about an error, try `rustc --explain E0007`.