Skip to content

Commit e5fb58e

Browse files
committed
Add compile-fail tests for unsound moving out of enums (#2329)
1 parent 5b25fc9 commit e5fb58e

7 files changed

+67
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
struct X { x: (); drop { error!("destructor runs"); } }
2+
3+
fn main() {
4+
let x = some(X { x: () });
5+
match move x {
6+
some(ref _y @ move _z) => { }, //~ ERROR cannot bind by-move and by-ref in the same pattern
7+
none => fail
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
struct X { x: (); drop { error!("destructor runs"); } }
2+
3+
fn main() {
4+
let x = some((X { x: () }, X { x: () }));
5+
match move x {
6+
some((ref _y, move _z)) => { }, //~ ERROR cannot bind by-move and by-ref in the same pattern
7+
none => fail
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct X { x: (); drop { error!("destructor runs"); } }
2+
3+
enum double_option<T,U> { some2(T,U), none2 }
4+
5+
fn main() {
6+
let x = some2(X { x: () }, X { x: () });
7+
match move x {
8+
some2(ref _y, move _z) => { }, //~ ERROR cannot bind by-move and by-ref in the same pattern
9+
none2 => fail
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn main() {
2+
let (c,p) = pipes::stream();
3+
let x = some(p);
4+
c.send(false);
5+
match move x {
6+
some(move z) if z.recv() => { fail }, //~ ERROR cannot bind by-move into a pattern guard
7+
some(move z) => { assert !z.recv(); },
8+
none => fail
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
struct X { x: (); drop { error!("destructor runs"); } }
2+
3+
fn main() {
4+
let x = some(X { x: () });
5+
match x {
6+
some(move _z) => { }, //~ ERROR cannot bind by-move when matching an lvalue
7+
none => fail
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
struct X { x: (); drop { error!("destructor runs"); } }
2+
struct Y { y: option<X>; }
3+
4+
fn main() {
5+
let x = Y { y: some(X { x: () }) };
6+
match x.y {
7+
some(move _z) => { }, //~ ERROR cannot bind by-move when matching an lvalue
8+
none => fail
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
struct X { x: (); drop { error!("destructor runs"); } }
2+
3+
fn main() {
4+
let x = some(X { x: () });
5+
match move x {
6+
some(move _y @ ref _z) => { }, //~ ERROR cannot bind by-move with sub-bindings
7+
none => fail
8+
}
9+
}

0 commit comments

Comments
 (0)