Add compile-fail tests for unsound moving out of enums (#2329)
This commit is contained in:
parent
5b25fc918a
commit
e5fb58e6c0
7 changed files with 67 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
10
src/test/compile-fail/bind-by-move-no-guards.rs
Normal file
10
src/test/compile-fail/bind-by-move-no-guards.rs
Normal file
|
@ -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
|
||||
}
|
||||
}
|
9
src/test/compile-fail/bind-by-move-no-lvalues-1.rs
Normal file
9
src/test/compile-fail/bind-by-move-no-lvalues-1.rs
Normal file
|
@ -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
|
||||
}
|
||||
}
|
10
src/test/compile-fail/bind-by-move-no-lvalues-2.rs
Normal file
10
src/test/compile-fail/bind-by-move-no-lvalues-2.rs
Normal file
|
@ -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
|
||||
}
|
||||
}
|
9
src/test/compile-fail/bind-by-move-no-sub-bindings.rs
Normal file
9
src/test/compile-fail/bind-by-move-no-sub-bindings.rs
Normal file
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue