about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2011-12-19 12:50:31 -0800
committerNiko Matsakis <niko@alum.mit.edu>2011-12-19 14:07:46 -0800
commit55a2fd18ec8f2e9aeee699296b7a500b49ff0c5e (patch)
treebbbe674e6f78eff5581363045d87f8ec856a534a /src/test
parent41ae146057431d99d5ab5c87d385dbf787a10ea2 (diff)
downloadrust-55a2fd18ec8f2e9aeee699296b7a500b49ff0c5e.tar.gz
rust-55a2fd18ec8f2e9aeee699296b7a500b49ff0c5e.zip
implement capture clauses (move, in particular) and integrate
them into type state and so forth
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/cap-clause-both-copy-and-move.rs5
-rw-r--r--src/test/compile-fail/cap-clause-double-copy.rs5
-rw-r--r--src/test/compile-fail/cap-clause-double-move.rs5
-rw-r--r--src/test/compile-fail/cap-clause-move-upvar.rs8
-rw-r--r--src/test/compile-fail/cap-clause-use-after-move.rs7
-rw-r--r--src/test/run-pass/cap-clause-move.rs17
-rw-r--r--src/test/run-pass/cap-clause-not-used.rs5
7 files changed, 52 insertions, 0 deletions
diff --git a/src/test/compile-fail/cap-clause-both-copy-and-move.rs b/src/test/compile-fail/cap-clause-both-copy-and-move.rs
new file mode 100644
index 00000000000..0758ad67bd5
--- /dev/null
+++ b/src/test/compile-fail/cap-clause-both-copy-and-move.rs
@@ -0,0 +1,5 @@
+// error-pattern:error: Variable 'x' captured more than once
+fn main() {
+    let x = 5;
+    let y = sendfn[move x; copy x]() -> int { x };
+}
\ No newline at end of file
diff --git a/src/test/compile-fail/cap-clause-double-copy.rs b/src/test/compile-fail/cap-clause-double-copy.rs
new file mode 100644
index 00000000000..2e1008bad1c
--- /dev/null
+++ b/src/test/compile-fail/cap-clause-double-copy.rs
@@ -0,0 +1,5 @@
+// error-pattern:error: Variable 'x' captured more than once
+fn main() {
+    let x = 5;
+    let y = sendfn[copy x, x]() -> int { x };
+}
diff --git a/src/test/compile-fail/cap-clause-double-move.rs b/src/test/compile-fail/cap-clause-double-move.rs
new file mode 100644
index 00000000000..89e1a4a5a51
--- /dev/null
+++ b/src/test/compile-fail/cap-clause-double-move.rs
@@ -0,0 +1,5 @@
+// error-pattern: error: Variable 'x' captured more than once
+fn main() {
+    let x = 5;
+    let y = sendfn[move x, x]() -> int { x };
+}
diff --git a/src/test/compile-fail/cap-clause-move-upvar.rs b/src/test/compile-fail/cap-clause-move-upvar.rs
new file mode 100644
index 00000000000..33b0a67a7e4
--- /dev/null
+++ b/src/test/compile-fail/cap-clause-move-upvar.rs
@@ -0,0 +1,8 @@
+// error-pattern: error: Upvars (like 'x') cannot be moved into a closure
+fn main() {
+    let x = 5;
+    let _y = sendfn[move x]() -> int {
+        let _z = sendfn[move x]() -> int { x };
+        22
+    };
+}
diff --git a/src/test/compile-fail/cap-clause-use-after-move.rs b/src/test/compile-fail/cap-clause-use-after-move.rs
new file mode 100644
index 00000000000..029b05ad2e1
--- /dev/null
+++ b/src/test/compile-fail/cap-clause-use-after-move.rs
@@ -0,0 +1,7 @@
+// error-pattern:Unsatisfied precondition constraint
+
+fn main() {
+    let x = 5;
+    let _y = sendfn[move x]() { };
+    let _z = x; //< error: Unsatisfied precondition constraint
+}
diff --git a/src/test/run-pass/cap-clause-move.rs b/src/test/run-pass/cap-clause-move.rs
new file mode 100644
index 00000000000..96b4b4d3aaa
--- /dev/null
+++ b/src/test/run-pass/cap-clause-move.rs
@@ -0,0 +1,17 @@
+// error-pattern: warning: Captured variable 'y' not used in closure
+fn main() {
+    let x = ~1;
+    let y = ptr::addr_of(*x) as uint;
+
+    let lam_copy = lambda[copy x]() -> uint { ptr::addr_of(*x) as uint };
+    let lam_move = lambda[move x]() -> uint { ptr::addr_of(*x) as uint };
+    assert lam_copy() != y;
+    assert lam_move() == y;
+
+    let x = ~2;
+    let y = ptr::addr_of(*x) as uint;
+    let snd_copy = sendfn[copy x]() -> uint { ptr::addr_of(*x) as uint };
+    let snd_move = sendfn[move x]() -> uint { ptr::addr_of(*x) as uint };
+    assert snd_copy() != y;
+    assert snd_move() == y;
+}
diff --git a/src/test/run-pass/cap-clause-not-used.rs b/src/test/run-pass/cap-clause-not-used.rs
new file mode 100644
index 00000000000..0bb43b9c6f5
--- /dev/null
+++ b/src/test/run-pass/cap-clause-not-used.rs
@@ -0,0 +1,5 @@
+// error-pattern: warning: Captured variable 'y' not used in closure
+fn main() {
+    let x = 5;
+    let _y = sendfn[copy x]() { };
+}