From 0034e6199e1ff234715aea73cdd31c9f149f334e Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sun, 15 Dec 2019 00:50:44 +0100 Subject: [PATCH] bindings_after_at: harden tests wrt. promotion --- .../borrowck-move-and-move.rs | 7 + .../borrowck-move-and-move.stderr | 33 +++- .../borrowck-pat-at-and-box.rs | 11 ++ .../borrowck-pat-at-and-box.stderr | 33 ++-- .../borrowck-pat-by-copy-bindings-in-at.rs | 12 +- .../borrowck-pat-by-move-and-ref.rs | 2 +- .../borrowck-pat-ref-both-sides.rs | 16 +- .../borrowck-pat-ref-mut-and-ref.rs | 14 ++ .../borrowck-pat-ref-mut-and-ref.stderr | 180 +++++++++++------- .../borrowck-pat-ref-mut-twice.rs | 12 ++ .../borrowck-pat-ref-mut-twice.stderr | 152 ++++++++------- 11 files changed, 307 insertions(+), 165 deletions(-) diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-move-and-move.rs b/src/test/ui/pattern/bindings-after-at/borrowck-move-and-move.rs index e18d3bc06a93..ba1c8e132f25 100644 --- a/src/test/ui/pattern/bindings-after-at/borrowck-move-and-move.rs +++ b/src/test/ui/pattern/bindings-after-at/borrowck-move-and-move.rs @@ -6,6 +6,9 @@ fn main() { struct U; // Not copy! + // Prevent promotion: + fn u() -> U { U } + let a @ b = U; //~^ ERROR cannot bind by-move with sub-bindings //~| ERROR use of moved value @@ -14,6 +17,10 @@ fn main() { //~^ ERROR cannot bind by-move with sub-bindings //~| ERROR use of moved value + let a @ (b, c) = (u(), u()); + //~^ ERROR cannot bind by-move with sub-bindings + //~| ERROR use of moved value + match Ok(U) { a @ Ok(b) | a @ Err(b) => {} //~^ ERROR cannot bind by-move with sub-bindings diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-move-and-move.stderr b/src/test/ui/pattern/bindings-after-at/borrowck-move-and-move.stderr index 0b69ff0b8392..f08692264e23 100644 --- a/src/test/ui/pattern/bindings-after-at/borrowck-move-and-move.stderr +++ b/src/test/ui/pattern/bindings-after-at/borrowck-move-and-move.stderr @@ -7,31 +7,37 @@ LL | #![feature(bindings_after_at)] = note: `#[warn(incomplete_features)]` on by default error[E0007]: cannot bind by-move with sub-bindings - --> $DIR/borrowck-move-and-move.rs:9:9 + --> $DIR/borrowck-move-and-move.rs:12:9 | LL | let a @ b = U; | ^^^^^ binds an already bound by-move value by moving it error[E0007]: cannot bind by-move with sub-bindings - --> $DIR/borrowck-move-and-move.rs:13:9 + --> $DIR/borrowck-move-and-move.rs:16:9 | LL | let a @ (b, c) = (U, U); | ^^^^^^^^^^ binds an already bound by-move value by moving it error[E0007]: cannot bind by-move with sub-bindings - --> $DIR/borrowck-move-and-move.rs:18:9 + --> $DIR/borrowck-move-and-move.rs:20:9 + | +LL | let a @ (b, c) = (u(), u()); + | ^^^^^^^^^^ binds an already bound by-move value by moving it + +error[E0007]: cannot bind by-move with sub-bindings + --> $DIR/borrowck-move-and-move.rs:25:9 | LL | a @ Ok(b) | a @ Err(b) => {} | ^^^^^^^^^ binds an already bound by-move value by moving it error[E0007]: cannot bind by-move with sub-bindings - --> $DIR/borrowck-move-and-move.rs:18:21 + --> $DIR/borrowck-move-and-move.rs:25:21 | LL | a @ Ok(b) | a @ Err(b) => {} | ^^^^^^^^^^ binds an already bound by-move value by moving it error[E0382]: use of moved value - --> $DIR/borrowck-move-and-move.rs:9:13 + --> $DIR/borrowck-move-and-move.rs:12:13 | LL | let a @ b = U; | ----^ - move occurs because value has type `main::U`, which does not implement the `Copy` trait @@ -40,7 +46,7 @@ LL | let a @ b = U; | value moved here error[E0382]: use of moved value - --> $DIR/borrowck-move-and-move.rs:13:17 + --> $DIR/borrowck-move-and-move.rs:16:17 | LL | let a @ (b, c) = (U, U); | --------^- ------ move occurs because value has type `(main::U, main::U)`, which does not implement the `Copy` trait @@ -49,7 +55,16 @@ LL | let a @ (b, c) = (U, U); | value moved here error[E0382]: use of moved value - --> $DIR/borrowck-move-and-move.rs:18:16 + --> $DIR/borrowck-move-and-move.rs:20:17 + | +LL | let a @ (b, c) = (u(), u()); + | --------^- ---------- move occurs because value has type `(main::U, main::U)`, which does not implement the `Copy` trait + | | | + | | value used here after move + | value moved here + +error[E0382]: use of moved value + --> $DIR/borrowck-move-and-move.rs:25:16 | LL | match Ok(U) { | ----- move occurs because value has type `std::result::Result`, which does not implement the `Copy` trait @@ -60,7 +75,7 @@ LL | a @ Ok(b) | a @ Err(b) => {} | value moved here error[E0382]: use of moved value - --> $DIR/borrowck-move-and-move.rs:18:29 + --> $DIR/borrowck-move-and-move.rs:25:29 | LL | match Ok(U) { | ----- move occurs because value has type `std::result::Result`, which does not implement the `Copy` trait @@ -70,7 +85,7 @@ LL | a @ Ok(b) | a @ Err(b) => {} | | value used here after move | value moved here -error: aborting due to 8 previous errors +error: aborting due to 10 previous errors Some errors have detailed explanations: E0007, E0382. For more information about an error, try `rustc --explain E0007`. diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.rs b/src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.rs index 7a4fe96b2133..cf765f579e00 100644 --- a/src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.rs +++ b/src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.rs @@ -7,6 +7,8 @@ #[derive(Copy, Clone)] struct C; +fn c() -> C { C } + fn main() { let a @ box &b = Box::new(&C); //~^ ERROR cannot bind by-move with sub-bindings @@ -21,14 +23,23 @@ fn main() { drop(b); drop(a); + let ref a @ box b = Box::new(c()); // OK; the type is `Copy`. + drop(b); + drop(b); + drop(a); + struct NC; + fn nc() -> NC { NC } + let ref a @ box b = Box::new(NC); //~ ERROR cannot bind by-move and by-ref in the same pattern let ref a @ box ref b = Box::new(NC); // OK. drop(a); drop(b); + 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 let ref a @ box ref mut b = Box::new(NC); diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.stderr b/src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.stderr index 7bb2379968e5..19cd0b7c1d39 100644 --- a/src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.stderr +++ b/src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.stderr @@ -7,19 +7,19 @@ LL | #![feature(bindings_after_at)] = note: `#[warn(incomplete_features)]` on by default error[E0007]: cannot bind by-move with sub-bindings - --> $DIR/borrowck-pat-at-and-box.rs:11:9 + --> $DIR/borrowck-pat-at-and-box.rs:13:9 | LL | let a @ box &b = Box::new(&C); | ^^^^^^^^^^ binds an already bound by-move value by moving it error[E0007]: cannot bind by-move with sub-bindings - --> $DIR/borrowck-pat-at-and-box.rs:15:9 + --> $DIR/borrowck-pat-at-and-box.rs:17:9 | LL | let a @ box b = Box::new(C); | ^^^^^^^^^ binds an already bound by-move value by moving it error[E0009]: cannot bind by-move and by-ref in the same pattern - --> $DIR/borrowck-pat-at-and-box.rs:26:21 + --> $DIR/borrowck-pat-at-and-box.rs:35:21 | LL | let ref a @ box b = Box::new(NC); | ------------^ @@ -28,7 +28,16 @@ LL | let ref a @ box b = Box::new(NC); | 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 + --> $DIR/borrowck-pat-at-and-box.rs:41: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:43:9 | LL | let ref a @ box ref mut b = Box::new(NC); | -----^^^^^^^--------- @@ -37,7 +46,7 @@ LL | let ref a @ box ref mut b = Box::new(NC); | 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 + --> $DIR/borrowck-pat-at-and-box.rs:45:9 | LL | let ref a @ box ref mut b = Box::new(NC); | -----^^^^^^^--------- @@ -46,7 +55,7 @@ LL | let ref a @ box ref mut b = Box::new(NC); | 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 + --> $DIR/borrowck-pat-at-and-box.rs:48:9 | LL | let ref a @ box ref mut b = Box::new(NC); | -----^^^^^^^--------- @@ -55,7 +64,7 @@ LL | let ref a @ box ref mut b = Box::new(NC); | 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 + --> $DIR/borrowck-pat-at-and-box.rs:54:9 | LL | let ref mut a @ box ref b = Box::new(NC); | ---------^^^^^^^----- @@ -64,7 +73,7 @@ LL | let ref mut a @ box ref b = Box::new(NC); | mutable borrow occurs here error[E0382]: use of moved value - --> $DIR/borrowck-pat-at-and-box.rs:11:18 + --> $DIR/borrowck-pat-at-and-box.rs:13:18 | LL | let a @ box &b = Box::new(&C); | ---------^ ------------ move occurs because value has type `std::boxed::Box<&C>`, which does not implement the `Copy` trait @@ -73,7 +82,7 @@ LL | let a @ box &b = Box::new(&C); | value moved here error[E0382]: use of moved value - --> $DIR/borrowck-pat-at-and-box.rs:15:17 + --> $DIR/borrowck-pat-at-and-box.rs:17:17 | LL | let a @ box b = Box::new(C); | --------^ ----------- move occurs because value has type `std::boxed::Box`, which does not implement the `Copy` trait @@ -82,7 +91,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:37:21 + --> $DIR/borrowck-pat-at-and-box.rs:48:21 | LL | let ref a @ box ref mut b = Box::new(NC); | ------------^^^^^^^^^ @@ -94,7 +103,7 @@ 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:43:25 + --> $DIR/borrowck-pat-at-and-box.rs:54:25 | LL | let ref mut a @ box ref b = Box::new(NC); | ----------------^^^^^ @@ -105,7 +114,7 @@ LL | let ref mut a @ box ref b = Box::new(NC); LL | *a = Box::new(NC); | -- mutable borrow later used here -error: aborting due to 11 previous errors +error: aborting due to 12 previous errors Some errors have detailed explanations: E0007, E0009, E0382, E0502. For more information about an error, try `rustc --explain E0007`. diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-copy-bindings-in-at.rs b/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-copy-bindings-in-at.rs index 1115dd5b5a28..4cdbfd636f35 100644 --- a/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-copy-bindings-in-at.rs +++ b/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-copy-bindings-in-at.rs @@ -9,6 +9,8 @@ #[derive(Copy, Clone)] struct C; +fn mk_c() -> C { C } + #[derive(Copy, Clone)] struct P(A, B); @@ -16,12 +18,12 @@ enum E { L(A), R(B) } fn main() { let a @ b @ c @ d = C; - let a @ (b, c) = (C, C); - let a @ P(b, P(c, d)) = P(C, P(C, C)); + let a @ (b, c) = (C, mk_c()); + let a @ P(b, P(c, d)) = P(mk_c(), P(C, C)); let a @ [b, c] = [C, C]; - let a @ [b, .., c] = [C, C, C]; + let a @ [b, .., c] = [C, mk_c(), C]; let a @ &(b, c) = &(C, C); - let a @ &(b, &P(c, d)) = &(C, &P(C, C)); + let a @ &(b, &P(c, d)) = &(mk_c(), &P(C, C)); use self::E::*; match L(C) { @@ -31,7 +33,7 @@ fn main() { drop(a); } } - match R(&L(&C)) { + match R(&L(&mk_c())) { L(L(&a)) | L(R(&a)) | R(L(&a)) | R(R(&a)) => { let a: C = a; drop(a); diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref.rs b/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref.rs index 4b7f61c365e3..5852e3072290 100644 --- a/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref.rs +++ b/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref.rs @@ -4,7 +4,7 @@ fn main() { match Some("hi".to_string()) { ref op_string_ref @ Some(s) => {}, - //~^ ERROR E0009 + //~^ ERROR cannot bind by-move and by-ref in the same pattern [E0009] None => {}, } } diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-both-sides.rs b/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-both-sides.rs index 5fbedd02d25e..3c501ad8f8a5 100644 --- a/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-both-sides.rs +++ b/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-both-sides.rs @@ -9,27 +9,35 @@ fn main() { struct U; // Not copy! + // Promotion: let ref a @ ref b = U; let _: &U = a; let _: &U = b; - let ref a @ (ref b, [ref c, ref d]) = (U, [U, U]); + // Prevent promotion: + fn u() -> U { U } + + let ref a @ ref b = u(); + let _: &U = a; + let _: &U = b; + + let ref a @ (ref b, [ref c, ref d]) = (u(), [u(), u()]); let _: &(U, [U; 2]) = a; let _: &U = b; let _: &U = c; let _: &U = d; - let a @ (b, [c, d]) = &(U, [U, U]); + let a @ (b, [c, d]) = &(u(), [u(), u()]); let _: &(U, [U; 2]) = a; let _: &U = b; let _: &U = c; let _: &U = d; - let ref a @ &ref b = &U; + let ref a @ &ref b = &u(); let _: &&U = a; let _: &U = b; - match Ok(U) { + match Ok(u()) { ref a @ Ok(ref b) | ref a @ Err(ref b) => { let _: &Result = a; let _: &U = b; diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.rs b/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.rs index 35dddfdbb1fb..54b4e1cae85c 100644 --- a/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.rs +++ b/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.rs @@ -19,6 +19,9 @@ fn main() { struct U; + // Prevent promotion: + fn u() -> U { U } + 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; @@ -28,6 +31,17 @@ fn main() { let ref mut a @ (ref b, ref c) = (U, U); //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable + let ref mut a @ ref b = u(); + //~^ 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 = u(); + drop(b); + let ref a @ ref mut b = u(); + //~^ 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 = u(); + drop(a); + let ref mut a @ ref b = U; //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable *a = U; diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.stderr b/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.stderr index 7059f3c7caa8..04944c1d528d 100644 --- a/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.stderr +++ b/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.stderr @@ -16,7 +16,7 @@ LL | ref mut z @ &mut Some(ref a) => { | 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 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:25:9 | LL | let ref a @ ref mut b = U; | -----^^^--------- @@ -25,7 +25,7 @@ LL | let ref a @ ref mut b = U; | 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 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:27:9 | LL | let ref mut a @ ref b = U; | ---------^^^----- @@ -34,7 +34,7 @@ LL | let ref mut a @ ref b = U; | 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 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:29:9 | LL | let ref a @ (ref mut b, ref mut c) = (U, U); | -----^^^^---------^^---------^ @@ -44,7 +44,7 @@ LL | let ref a @ (ref mut b, ref mut c) = (U, U); | 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 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:31:9 | LL | let ref mut a @ (ref b, ref c) = (U, U); | ---------^^^^-----^^-----^ @@ -54,7 +54,25 @@ LL | let ref mut a @ (ref b, ref c) = (U, U); | 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 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:34: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:39: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:45:9 | LL | let ref mut a @ ref b = U; | ---------^^^----- @@ -63,7 +81,7 @@ LL | let ref mut a @ ref b = U; | 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 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:49:9 | LL | let ref a @ ref mut b = U; | -----^^^--------- @@ -72,7 +90,7 @@ LL | let ref a @ ref mut b = U; | 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 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:55:9 | LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) => { | ---------^^^^^^-----^ @@ -81,7 +99,7 @@ LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) => { | 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 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:55:33 | LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) => { | ---------^^^^^^^-----^ @@ -90,7 +108,7 @@ LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) => { | 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 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:64:9 | LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => { | -----^^^^^^---------^ @@ -99,7 +117,7 @@ LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => { | 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 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:64:33 | LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => { | -----^^^^^^^---------^ @@ -107,46 +125,10 @@ 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 } => {} +LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false } => {} | -----^^^^^^---------^ | | | | | mutable borrow occurs here @@ -155,7 +137,7 @@ LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false 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 } => {} +LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false } => {} | -----^^^^^^^---------^ | | | | | mutable borrow occurs here @@ -164,7 +146,7 @@ LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false 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 } => {} +LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { *a = Err(U); false } => {} | ---------^^^^^^-----^ | | | | | immutable borrow occurs here @@ -173,7 +155,7 @@ LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false 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 } => {} +LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { *a = Err(U); false } => {} | ---------^^^^^^^-----^ | | | | | immutable borrow occurs here @@ -182,15 +164,41 @@ LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false 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 +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:94:9 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:89: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:96: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:96: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:103:9 | LL | let ref a @ (ref mut b, ref mut c) = (U, U); | -----^^^^---------^^---------^ @@ -200,7 +208,17 @@ LL | let ref a @ (ref mut b, ref mut c) = (U, U); | 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 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:108: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:115:9 | LL | let ref a @ (ref mut b, ref mut c) = (U, U); | -----^^^^---------^^---------^ @@ -210,7 +228,7 @@ LL | let ref a @ (ref mut b, ref mut c) = (U, U); | 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 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:120:9 | LL | let ref mut a @ (ref b, ref c) = (U, U); | ---------^^^^-----^^-----^ @@ -231,8 +249,32 @@ LL | ref mut z @ &mut Some(ref a) => { LL | **z = None; | ---------- mutable borrow later used here +error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:34:21 + | +LL | let ref mut a @ ref b = u(); + | ------------^^^^^ + | | | + | | immutable borrow occurs here + | mutable borrow occurs here +... +LL | *a = u(); + | -------- 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:50:20 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:39:17 + | +LL | let ref a @ ref mut b = u(); + | --------^^^^^^^^^ + | | | + | | mutable borrow occurs here + | immutable borrow occurs here +... +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:64:20 | LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => { | -----------^^^^^^^^^- @@ -244,7 +286,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:50:45 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:64:45 | LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => { | ------------^^^^^^^^^- @@ -256,7 +298,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:61:61 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:75:61 | LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false } => {} | ^^^^^^ cannot assign @@ -264,7 +306,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:68:61 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:82:61 | LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { *a = Err(U); false } => {} | ^^^^^^^^^^^ cannot assign @@ -272,7 +314,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:75:66 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:89: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 @@ -280,7 +322,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:82:66 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:96: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`, which does not implement the `Copy` trait @@ -288,7 +330,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:94:18 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:108:18 | LL | let ref a @ (ref mut b, ref mut c) = (U, U); | ---------^^^^^^^^^------------ @@ -300,7 +342,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:94:29 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:108:29 | LL | let ref a @ (ref mut b, ref mut c) = (U, U); | --------------------^^^^^^^^^- @@ -312,7 +354,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:101:18 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:115:18 | LL | let ref a @ (ref mut b, ref mut c) = (U, U); | ---------^^^^^^^^^------------ @@ -324,7 +366,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:101:29 + --> $DIR/borrowck-pat-ref-mut-and-ref.rs:115:29 | LL | let ref a @ (ref mut b, ref mut c) = (U, U); | --------------------^^^^^^^^^- @@ -335,7 +377,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 34 previous errors +error: aborting due to 38 previous errors Some errors have detailed explanations: E0502, E0507, E0594. For more information about an error, try `rustc --explain E0502`. diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-twice.rs b/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-twice.rs index f76d9ce73cf2..487ac4b852b6 100644 --- a/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-twice.rs +++ b/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-twice.rs @@ -6,6 +6,8 @@ fn main() { struct U; + fn u() -> U { U } + let ref mut a @ ref mut b = U; //~^ ERROR cannot borrow `a` as mutable more than once at a time //~| ERROR cannot borrow `_` as mutable more than once at a time @@ -34,6 +36,16 @@ fn main() { ] ) = (U, [U, U, U]); + 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 //~| ERROR borrow of moved value diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-twice.stderr b/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-twice.stderr index e8176342a0c4..011e18be8b29 100644 --- a/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-twice.stderr +++ b/src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-twice.stderr @@ -7,7 +7,7 @@ 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 + --> $DIR/borrowck-pat-ref-mut-twice.rs:11:9 | LL | let ref mut a @ ref mut b = U; | ---------^^^--------- @@ -16,7 +16,7 @@ LL | let ref mut a @ ref mut b = U; | 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 + --> $DIR/borrowck-pat-ref-mut-twice.rs:15:9 | LL | let ref mut a @ ref mut b = U; | ---------^^^--------- @@ -25,7 +25,7 @@ LL | let ref mut a @ ref mut b = U; | 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 + --> $DIR/borrowck-pat-ref-mut-twice.rs:18:9 | LL | let ref mut a @ ref mut b = U; | ---------^^^--------- @@ -34,7 +34,7 @@ LL | let ref mut a @ ref mut b = U; | 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 + --> $DIR/borrowck-pat-ref-mut-twice.rs:21:9 | LL | let ref mut a @ ref mut b = U; | ---------^^^--------- @@ -43,7 +43,7 @@ LL | let ref mut a @ ref mut b = U; | 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 + --> $DIR/borrowck-pat-ref-mut-twice.rs:25:9 | LL | let ref mut a @ ref mut b = U; | ---------^^^--------- @@ -52,7 +52,7 @@ LL | let ref mut a @ ref mut b = U; | 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 + --> $DIR/borrowck-pat-ref-mut-twice.rs:29:9 | LL | let ref mut a @ ( | ^-------- @@ -73,32 +73,54 @@ LL | | ] LL | | ) = (U, [U, U, U]); | |_____^ +error: cannot borrow `a` as mutable more than once at a time + --> $DIR/borrowck-pat-ref-mut-twice.rs:39: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:37:9 + --> $DIR/borrowck-pat-ref-mut-twice.rs:49: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:41:9 + --> $DIR/borrowck-pat-ref-mut-twice.rs:53: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:45:9 + --> $DIR/borrowck-pat-ref-mut-twice.rs:57: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:48:9 + --> $DIR/borrowck-pat-ref-mut-twice.rs:60: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 + --> $DIR/borrowck-pat-ref-mut-twice.rs:65:9 | LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => { | ---------^^^^^^---------^ @@ -107,7 +129,7 @@ LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => { | 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 + --> $DIR/borrowck-pat-ref-mut-twice.rs:65:37 | LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => { | ---------^^^^^^^---------^ @@ -116,7 +138,7 @@ LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => { | 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 + --> $DIR/borrowck-pat-ref-mut-twice.rs:71:9 | LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => { | ---------^^^^^^---------^ @@ -125,25 +147,7 @@ LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => { | 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 + --> $DIR/borrowck-pat-ref-mut-twice.rs:71:37 | LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => { | ---------^^^^^^^---------^ @@ -169,8 +173,26 @@ 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:90: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:90: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 + --> $DIR/borrowck-pat-ref-mut-twice.rs:11:21 | LL | let ref mut a @ ref mut b = U; | ------------^^^^^^^^^ @@ -182,7 +204,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:19:21 + --> $DIR/borrowck-pat-ref-mut-twice.rs:21:21 | LL | let ref mut a @ ref mut b = U; | ------------^^^^^^^^^ @@ -194,7 +216,7 @@ LL | *a = U; | ------ first borrow later used here error[E0382]: borrow of moved value - --> $DIR/borrowck-pat-ref-mut-twice.rs:37:25 + --> $DIR/borrowck-pat-ref-mut-twice.rs:49: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 @@ -203,7 +225,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:41:21 + --> $DIR/borrowck-pat-ref-mut-twice.rs:53: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 @@ -212,7 +234,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:45:18 + --> $DIR/borrowck-pat-ref-mut-twice.rs:57: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 @@ -221,7 +243,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:48:30 + --> $DIR/borrowck-pat-ref-mut-twice.rs:60: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 @@ -229,30 +251,6 @@ LL | let a @ &mut (ref mut b, ref mut c) = &mut (U, U); | | value borrowed here after move | value moved here -error[E0499]: cannot borrow `_` as mutable more than once at a time - --> $DIR/borrowck-pat-ref-mut-twice.rs:66:24 - | -LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => { - | ---------------^^^^^^^^^- - | | | - | | second mutable borrow occurs here - | first mutable borrow occurs here -... -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:66:53 - | -LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => { - | ----------------^^^^^^^^^- - | | | - | | second mutable borrow occurs here - | first mutable borrow occurs here -... -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:78:24 | @@ -262,8 +260,8 @@ LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => { | | second mutable borrow occurs here | first mutable borrow occurs here ... -LL | drop(a); - | - first borrow later used here +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:78:53 @@ -274,10 +272,34 @@ LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => { | | second mutable borrow occurs here | first mutable borrow occurs here ... +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:90:24 + | +LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => { + | ---------------^^^^^^^^^- + | | | + | | second mutable borrow occurs here + | first mutable borrow occurs here +... LL | drop(a); | - first borrow later used here -error: aborting due to 28 previous errors +error[E0499]: cannot borrow `_` as mutable more than once at a time + --> $DIR/borrowck-pat-ref-mut-twice.rs:90:53 + | +LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => { + | ----------------^^^^^^^^^- + | | | + | | second mutable borrow occurs here + | first mutable borrow occurs here +... +LL | drop(a); + | - first borrow later used here + +error: aborting due to 29 previous errors Some errors have detailed explanations: E0007, E0382, E0499. For more information about an error, try `rustc --explain E0007`.