diff --git a/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-1.rs b/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-1.rs new file mode 100644 index 000000000000..0ee3cac5180f --- /dev/null +++ b/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-1.rs @@ -0,0 +1,9 @@ +struct X { x: (); drop { error!("destructor runs"); } } + +fn main() { + let x = some(X { x: () }); + match move x { + some(ref _y @ move _z) => { }, //~ ERROR cannot bind by-move and by-ref in the same pattern + none => fail + } +} diff --git a/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-2.rs b/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-2.rs new file mode 100644 index 000000000000..9752ae1b3576 --- /dev/null +++ b/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-2.rs @@ -0,0 +1,9 @@ +struct X { x: (); drop { error!("destructor runs"); } } + +fn main() { + let x = some((X { x: () }, X { x: () })); + match move x { + some((ref _y, move _z)) => { }, //~ ERROR cannot bind by-move and by-ref in the same pattern + none => fail + } +} diff --git a/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-3.rs b/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-3.rs new file mode 100644 index 000000000000..399e8702b907 --- /dev/null +++ b/src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-3.rs @@ -0,0 +1,11 @@ +struct X { x: (); drop { error!("destructor runs"); } } + +enum double_option { some2(T,U), none2 } + +fn main() { + let x = some2(X { x: () }, X { x: () }); + match move x { + some2(ref _y, move _z) => { }, //~ ERROR cannot bind by-move and by-ref in the same pattern + none2 => fail + } +} diff --git a/src/test/compile-fail/bind-by-move-no-guards.rs b/src/test/compile-fail/bind-by-move-no-guards.rs new file mode 100644 index 000000000000..e3fb330990e9 --- /dev/null +++ b/src/test/compile-fail/bind-by-move-no-guards.rs @@ -0,0 +1,10 @@ +fn main() { + let (c,p) = pipes::stream(); + let x = some(p); + c.send(false); + match move x { + some(move z) if z.recv() => { fail }, //~ ERROR cannot bind by-move into a pattern guard + some(move z) => { assert !z.recv(); }, + none => fail + } +} diff --git a/src/test/compile-fail/bind-by-move-no-lvalues-1.rs b/src/test/compile-fail/bind-by-move-no-lvalues-1.rs new file mode 100644 index 000000000000..bd7fd843ed56 --- /dev/null +++ b/src/test/compile-fail/bind-by-move-no-lvalues-1.rs @@ -0,0 +1,9 @@ +struct X { x: (); drop { error!("destructor runs"); } } + +fn main() { + let x = some(X { x: () }); + match x { + some(move _z) => { }, //~ ERROR cannot bind by-move when matching an lvalue + none => fail + } +} diff --git a/src/test/compile-fail/bind-by-move-no-lvalues-2.rs b/src/test/compile-fail/bind-by-move-no-lvalues-2.rs new file mode 100644 index 000000000000..ecd684719fe4 --- /dev/null +++ b/src/test/compile-fail/bind-by-move-no-lvalues-2.rs @@ -0,0 +1,10 @@ +struct X { x: (); drop { error!("destructor runs"); } } +struct Y { y: option; } + +fn main() { + let x = Y { y: some(X { x: () }) }; + match x.y { + some(move _z) => { }, //~ ERROR cannot bind by-move when matching an lvalue + none => fail + } +} diff --git a/src/test/compile-fail/bind-by-move-no-sub-bindings.rs b/src/test/compile-fail/bind-by-move-no-sub-bindings.rs new file mode 100644 index 000000000000..88c995874aa8 --- /dev/null +++ b/src/test/compile-fail/bind-by-move-no-sub-bindings.rs @@ -0,0 +1,9 @@ +struct X { x: (); drop { error!("destructor runs"); } } + +fn main() { + let x = some(X { x: () }); + match move x { + some(move _y @ ref _z) => { }, //~ ERROR cannot bind by-move with sub-bindings + none => fail + } +}