summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-01-11 13:24:30 -0800
committerNiko Matsakis <niko@alum.mit.edu>2012-03-02 06:47:25 -0800
commit12c68bcd6df325cc369adce018c07dfe3e2b767a (patch)
tree5f0136c67cf30df88601a837fe5559dcdddf0fb8 /src/test
parent8478349b8be3b15d50569f55bd97ef2d62786fe4 (diff)
make sure we do not bind unique closures (or blocks, for that matter)
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/bind-stack-closure.rs10
-rw-r--r--src/test/compile-fail/bind-unique-closure.rs22
2 files changed, 32 insertions, 0 deletions
diff --git a/src/test/compile-fail/bind-stack-closure.rs b/src/test/compile-fail/bind-stack-closure.rs
new file mode 100644
index 00000000000..6a08b9b56c0
--- /dev/null
+++ b/src/test/compile-fail/bind-stack-closure.rs
@@ -0,0 +1,10 @@
+fn foo(x: fn()) {
+    bind x(); //! ERROR cannot bind fn closures
+}
+
+fn bar(x: fn&()) {
+    bind x(); //! ERROR cannot bind fn& closures
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/bind-unique-closure.rs b/src/test/compile-fail/bind-unique-closure.rs
new file mode 100644
index 00000000000..233c92b7bb3
--- /dev/null
+++ b/src/test/compile-fail/bind-unique-closure.rs
@@ -0,0 +1,22 @@
+// -*- rust -*-
+
+// I originally made this test to ensure that bind does the right
+// thing when binding a unique closure (which is to copy the closure,
+// I suppose?).  But I've since decided it's not worth the effort, and
+// so I just made it a simple error.  But I left the test as is in
+// case we ever decide that bind should work with unique closures,
+// though a simpler test would suffice for now.
+
+fn make_addr(-x: ~int) -> fn~() -> uint {
+    (fn~[move x]() -> uint { ptr::addr_of(*x) as uint })
+}
+
+fn main() {
+    let x = ~3;
+    let a = ptr::addr_of(*x) as uint;
+    let adder: fn~() -> uint = make_addr(x);
+    let bound_adder: fn~() -> uint = bind adder();
+    //!^ ERROR cannot bind fn~ closures
+    assert adder() == a;
+    assert bound_adder() != a;
+}