diff options
Diffstat (limited to 'src')
7 files changed, 67 insertions, 0 deletions
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 00000000000..0ee3cac5180 --- /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 00000000000..9752ae1b357 --- /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 00000000000..399e8702b90 --- /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<T,U> { 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 00000000000..e3fb330990e --- /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 00000000000..bd7fd843ed5 --- /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 00000000000..ecd684719fe --- /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<X>; } + +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 00000000000..88c995874aa --- /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 + } +} |
