diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box-pass.rs b/src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box-pass.rs new file mode 100644 index 000000000000..d88ca2459bb9 --- /dev/null +++ b/src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box-pass.rs @@ -0,0 +1,77 @@ +// check-pass + +// Test `@` patterns combined with `box` patterns. + +#![feature(bindings_after_at)] +//~^ WARN the feature `bindings_after_at` is incomplete and may cause the compiler to crash +#![feature(box_patterns)] +#![feature(slice_patterns)] + +#[derive(Copy, Clone)] +struct C; + +fn c() -> C { C } + +struct NC; + +fn nc() -> NC { NC } + +fn main() { + let ref a @ box b = Box::new(C); // OK; the type is `Copy`. + drop(b); + drop(b); + drop(a); + + let ref a @ box b = Box::new(c()); // OK; the type is `Copy`. + drop(b); + drop(b); + drop(a); + + fn f3(ref a @ box b: Box) { // OK; the type is `Copy`. + drop(b); + drop(b); + drop(a); + } + match Box::new(c()) { + ref a @ box b => { // OK; the type is `Copy`. + drop(b); + drop(b); + drop(a); + } + } + + let ref a @ box ref b = Box::new(NC); // OK. + drop(a); + drop(b); + + fn f4(ref a @ box ref b: Box) { // OK. + drop(a); + drop(b) + } + + match Box::new(nc()) { + ref a @ box ref b => { // OK. + drop(a); + drop(b); + } + } + + match Box::new([Ok(c()), Err(nc()), Ok(c())]) { + box [Ok(a), ref xs @ .., Err(ref b)] => { + let _: C = a; + let _: &[Result; 1] = xs; + let _: &NC = b; + } + _ => {} + } + + match [Ok(Box::new(c())), Err(Box::new(nc())), Ok(Box::new(c())), Ok(Box::new(c()))] { + [Ok(box a), ref xs @ .., Err(box ref b), Err(box ref c)] => { + let _: C = a; + let _: &[Result, Box>; 1] = xs; + let _: &NC = b; + let _: &NC = c; + } + _ => {} + } +} diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box-pass.stderr b/src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box-pass.stderr new file mode 100644 index 000000000000..e981b3428a72 --- /dev/null +++ b/src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box-pass.stderr @@ -0,0 +1,8 @@ +warning: the feature `bindings_after_at` is incomplete and may cause the compiler to crash + --> $DIR/borrowck-pat-at-and-box-pass.rs:5:12 + | +LL | #![feature(bindings_after_at)] + | ^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + 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 8512c7f9b696..32fb962b55c2 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 @@ -3,6 +3,7 @@ #![feature(bindings_after_at)] //~^ WARN the feature `bindings_after_at` is incomplete and may cause the compiler to crash #![feature(box_patterns)] +#![feature(slice_patterns)] #[derive(Copy, Clone)] struct C; @@ -34,47 +35,8 @@ fn main() { //~^ ERROR cannot bind by-move with sub-bindings //~| ERROR use of moved value - let ref a @ box b = Box::new(C); // OK; the type is `Copy`. - drop(b); - drop(b); - drop(a); - - let ref a @ box b = Box::new(c()); // OK; the type is `Copy`. - drop(b); - drop(b); - drop(a); - - fn f3(ref a @ box b: Box) { // OK; the type is `Copy`. - drop(b); - drop(b); - drop(a); - } - match Box::new(c()) { - ref a @ box b => { // OK; the type is `Copy`. - drop(b); - drop(b); - drop(a); - } - } - 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); - - fn f4(ref a @ box ref b: Box) { // OK. - drop(a); - drop(b) - } - - match Box::new(nc()) { - ref a @ box ref b => { // 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); @@ -109,4 +71,16 @@ fn main() { drop(b); } } + + match Box::new([Ok(c()), Err(nc()), Ok(c())]) { + box [Ok(a), ref xs @ .., Err(b)] => {} + //~^ ERROR cannot bind by-move and by-ref in the same pattern + _ => {} + } + + match [Ok(Box::new(c())), Err(Box::new(nc())), Ok(Box::new(c())), Ok(Box::new(c()))] { + [Ok(box ref a), ref xs @ .., Err(box b), Err(box ref mut c)] => {} + //~^ ERROR cannot bind by-move and by-ref in the same pattern + _ => {} + } } 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 512e75982cb5..05e80085e6b9 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,25 +7,25 @@ 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:17:9 + --> $DIR/borrowck-pat-at-and-box.rs:18: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:21:9 + --> $DIR/borrowck-pat-at-and-box.rs:22: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:33:25 + --> $DIR/borrowck-pat-at-and-box.rs:34:25 | LL | match Box::new(C) { a @ box b => {} } | ^^^^^^^^^ 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:60:21 + --> $DIR/borrowck-pat-at-and-box.rs:38:21 | LL | let ref a @ box b = Box::new(NC); | ------------^ @@ -34,7 +34,7 @@ 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:78:9 + --> $DIR/borrowck-pat-at-and-box.rs:40:9 | LL | let ref a @ box ref mut b = Box::new(nc()); | -----^^^^^^^--------- @@ -43,7 +43,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:80:9 + --> $DIR/borrowck-pat-at-and-box.rs:42:9 | LL | let ref a @ box ref mut b = Box::new(NC); | -----^^^^^^^--------- @@ -52,7 +52,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:82:9 + --> $DIR/borrowck-pat-at-and-box.rs:44:9 | LL | let ref a @ box ref mut b = Box::new(NC); | -----^^^^^^^--------- @@ -61,7 +61,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:85:9 + --> $DIR/borrowck-pat-at-and-box.rs:47:9 | LL | let ref a @ box ref mut b = Box::new(NC); | -----^^^^^^^--------- @@ -70,7 +70,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:91:9 + --> $DIR/borrowck-pat-at-and-box.rs:53:9 | LL | let ref mut a @ box ref b = Box::new(NC); | ---------^^^^^^^----- @@ -79,7 +79,7 @@ LL | let ref mut a @ box ref b = Box::new(NC); | mutable borrow occurs here error: cannot borrow `a` as immutable because it is also borrowed as mutable - --> $DIR/borrowck-pat-at-and-box.rs:105:9 + --> $DIR/borrowck-pat-at-and-box.rs:67:9 | LL | ref mut a @ box ref b => { | ---------^^^^^^^----- @@ -87,20 +87,38 @@ LL | ref mut a @ box ref b => { | | immutable borrow occurs here | mutable borrow occurs here +error[E0009]: cannot bind by-move and by-ref in the same pattern + --> $DIR/borrowck-pat-at-and-box.rs:76:38 + | +LL | box [Ok(a), ref xs @ .., Err(b)] => {} + | ----------- ^ by-move pattern here + | | + | by-ref pattern here + +error[E0009]: cannot bind by-move and by-ref in the same pattern + --> $DIR/borrowck-pat-at-and-box.rs:82:46 + | +LL | [Ok(box ref a), ref xs @ .., Err(box b), Err(box ref mut c)] => {} + | ----- ----------- ^ --------- by-ref pattern here + | | | | + | | | by-move pattern here + | | by-ref pattern here + | by-ref pattern here + error[E0007]: cannot bind by-move with sub-bindings - --> $DIR/borrowck-pat-at-and-box.rs:25:11 + --> $DIR/borrowck-pat-at-and-box.rs:26:11 | LL | fn f1(a @ box &b: Box<&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:29:11 + --> $DIR/borrowck-pat-at-and-box.rs:30:11 | LL | fn f2(a @ box b: Box) {} | ^^^^^^^^^ binds an already bound by-move value by moving it error: cannot borrow `a` as immutable because it is also borrowed as mutable - --> $DIR/borrowck-pat-at-and-box.rs:97:11 + --> $DIR/borrowck-pat-at-and-box.rs:59:11 | LL | fn f5(ref mut a @ box ref b: Box) { | ---------^^^^^^^----- @@ -109,7 +127,7 @@ LL | fn f5(ref mut a @ box ref b: Box) { | mutable borrow occurs here error[E0382]: use of moved value - --> $DIR/borrowck-pat-at-and-box.rs:17:18 + --> $DIR/borrowck-pat-at-and-box.rs:18: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 @@ -118,7 +136,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:21:17 + --> $DIR/borrowck-pat-at-and-box.rs:22: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 @@ -127,7 +145,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:33:33 + --> $DIR/borrowck-pat-at-and-box.rs:34:33 | LL | match Box::new(C) { a @ box b => {} } | ----------- --------^ @@ -137,7 +155,7 @@ LL | match Box::new(C) { a @ box b => {} } | move occurs because value has type `std::boxed::Box`, which does not implement the `Copy` trait error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable - --> $DIR/borrowck-pat-at-and-box.rs:85:21 + --> $DIR/borrowck-pat-at-and-box.rs:47:21 | LL | let ref a @ box ref mut b = Box::new(NC); | ------------^^^^^^^^^ @@ -149,7 +167,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:91:25 + --> $DIR/borrowck-pat-at-and-box.rs:53:25 | LL | let ref mut a @ box ref b = Box::new(NC); | ----------------^^^^^ @@ -161,7 +179,7 @@ LL | *a = Box::new(NC); | -- mutable borrow later used here error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable - --> $DIR/borrowck-pat-at-and-box.rs:105:25 + --> $DIR/borrowck-pat-at-and-box.rs:67:25 | LL | ref mut a @ box ref b => { | ----------------^^^^^ @@ -173,7 +191,7 @@ LL | *a = Box::new(NC); | -- mutable borrow later used here error[E0382]: use of moved value - --> $DIR/borrowck-pat-at-and-box.rs:25:20 + --> $DIR/borrowck-pat-at-and-box.rs:26:20 | LL | fn f1(a @ box &b: Box<&C>) {} | ---------^ @@ -183,7 +201,7 @@ LL | fn f1(a @ box &b: Box<&C>) {} | move occurs because value has type `std::boxed::Box<&C>`, which does not implement the `Copy` trait error[E0382]: use of moved value - --> $DIR/borrowck-pat-at-and-box.rs:29:19 + --> $DIR/borrowck-pat-at-and-box.rs:30:19 | LL | fn f2(a @ box b: Box) {} | --------^ @@ -193,7 +211,7 @@ LL | fn f2(a @ box b: Box) {} | move occurs because value has type `std::boxed::Box`, which does not implement the `Copy` trait error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable - --> $DIR/borrowck-pat-at-and-box.rs:97:27 + --> $DIR/borrowck-pat-at-and-box.rs:59:27 | LL | fn f5(ref mut a @ box ref b: Box) { | ----------------^^^^^ @@ -204,7 +222,7 @@ LL | fn f5(ref mut a @ box ref b: Box) { LL | *a = Box::new(NC); | -- mutable borrow later used here -error: aborting due to 22 previous errors +error: aborting due to 24 previous errors Some errors have detailed explanations: E0007, E0009, E0382, E0502. For more information about an error, try `rustc --explain E0007`.