about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBen Blum <bblum@andrew.cmu.edu>2012-08-22 19:02:08 -0400
committerBen Blum <bblum@andrew.cmu.edu>2012-08-22 20:40:25 -0400
commite5fb58e6c09202df314d3ef6ccb797f2cc8401e2 (patch)
tree239ef5a5a6fd7d275426a87ddae229812bbd8c09 /src
parent5b25fc918a8b91322c28242d3956109001b0f7c4 (diff)
Add compile-fail tests for unsound moving out of enums (#2329)
Diffstat (limited to 'src')
-rw-r--r--src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-1.rs9
-rw-r--r--src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-2.rs9
-rw-r--r--src/test/compile-fail/bind-by-move-neither-can-live-while-the-other-survives-3.rs11
-rw-r--r--src/test/compile-fail/bind-by-move-no-guards.rs10
-rw-r--r--src/test/compile-fail/bind-by-move-no-lvalues-1.rs9
-rw-r--r--src/test/compile-fail/bind-by-move-no-lvalues-2.rs10
-rw-r--r--src/test/compile-fail/bind-by-move-no-sub-bindings.rs9
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
+    }
+}