1
Fork 0

Add compile-fail tests for unsound moving out of enums (#2329)

This commit is contained in:
Ben Blum 2012-08-22 19:02:08 -04:00
parent 5b25fc918a
commit e5fb58e6c0
7 changed files with 67 additions and 0 deletions

View file

@ -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
}
}

View file

@ -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
}
}

View file

@ -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
}
}

View 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
}
}

View 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
}
}

View 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
}
}

View 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
}
}