diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-15 04:09:47 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-23 14:47:20 +0100 |
| commit | 427b1c33e993b55136ac8323600f9e3c714df3f4 (patch) | |
| tree | c22f10162a9129fdcef84a33e75774b9f4e4eb31 | |
| parent | 6fa8f4a57b8fb1f2be4b49bb5f87629389252020 (diff) | |
| download | rust-427b1c33e993b55136ac8323600f9e3c714df3f4.tar.gz rust-427b1c33e993b55136ac8323600f9e3c714df3f4.zip | |
clarify bind-by-move-neither-can-livee..
2 files changed, 72 insertions, 4 deletions
diff --git a/src/test/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.rs b/src/test/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.rs index 53d16e7ad3e..e86db3ab96f 100644 --- a/src/test/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.rs +++ b/src/test/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.rs @@ -1,3 +1,7 @@ +// This test is taken directly from #16053. +// It checks that you cannot use an AND-pattern (`binding @ pat`) +// where one side is by-ref and the other is by-move. + #![feature(bindings_after_at)] //~^ WARN the feature `bindings_after_at` is incomplete and may cause the compiler to crash @@ -9,4 +13,24 @@ fn main() { Some(ref _y @ _z) => { }, //~ ERROR cannot bind by-move and by-ref in the same pattern None => panic!() } + + let x = Some(X { x: () }); + match x { + Some(_z @ ref _y) => { }, //~ ERROR cannot bind by-move with sub-bindings + //~^ ERROR borrow of moved value + None => panic!() + } + + let mut x = Some(X { x: () }); + match x { + Some(ref mut _y @ _z) => { }, //~ ERROR cannot bind by-move and by-ref in the same pattern + None => panic!() + } + + let mut x = Some(X { x: () }); + match x { + Some(_z @ ref mut _y) => { }, //~ ERROR cannot bind by-move with sub-bindings + //~^ ERROR borrow of moved value + None => panic!() + } } diff --git a/src/test/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.stderr b/src/test/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.stderr index 63866238f56..658b77ed1ab 100644 --- a/src/test/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.stderr +++ b/src/test/ui/pattern/bindings-after-at/bind-by-move-neither-can-live-while-the-other-survives-1.stderr @@ -1,5 +1,5 @@ warning: the feature `bindings_after_at` is incomplete and may cause the compiler to crash - --> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:1:12 + --> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:5:12 | LL | #![feature(bindings_after_at)] | ^^^^^^^^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | #![feature(bindings_after_at)] = note: `#[warn(incomplete_features)]` on by default error[E0009]: cannot bind by-move and by-ref in the same pattern - --> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:9:23 + --> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:13:23 | LL | Some(ref _y @ _z) => { }, | ---------^^ @@ -15,6 +15,50 @@ LL | Some(ref _y @ _z) => { }, | | by-move pattern here | by-ref pattern here -error: aborting due to previous error +error[E0007]: cannot bind by-move with sub-bindings + --> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:19:14 + | +LL | Some(_z @ ref _y) => { }, + | ^^^^^^^^^^^ binds an already bound by-move value by moving it + +error[E0009]: cannot bind by-move and by-ref in the same pattern + --> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:26:27 + | +LL | Some(ref mut _y @ _z) => { }, + | -------------^^ + | | | + | | by-move pattern here + | by-ref pattern here + +error[E0007]: cannot bind by-move with sub-bindings + --> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:32:14 + | +LL | Some(_z @ ref mut _y) => { }, + | ^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it + +error[E0382]: borrow of moved value + --> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:19:19 + | +LL | Some(_z @ ref _y) => { }, + | -----^^^^^^ + | | | + | | value borrowed here after move + | value moved here + | + = note: move occurs because value has type `X`, which does not implement the `Copy` trait + +error[E0382]: borrow of moved value + --> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:32:19 + | +LL | Some(_z @ ref mut _y) => { }, + | -----^^^^^^^^^^ + | | | + | | value borrowed here after move + | value moved here + | + = note: move occurs because value has type `X`, which does not implement the `Copy` trait + +error: aborting due to 6 previous errors -For more information about this error, try `rustc --explain E0009`. +Some errors have detailed explanations: E0007, E0009, E0382. +For more information about an error, try `rustc --explain E0007`. |
