about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Koropoff <bkoropoff@gmail.com>2014-10-04 15:47:16 -0700
committerBrian Koropoff <bkoropoff@gmail.com>2014-10-05 00:26:06 -0700
commit4d2ff432e45eedef9d15618b0b9af5378994bc46 (patch)
tree422ee3cabe01a419dec7b215044b35c1f5e0a592
parent16b27bbeadff1c61ce36e09180b18aedc7ec27b2 (diff)
downloadrust-4d2ff432e45eedef9d15618b0b9af5378994bc46.tar.gz
rust-4d2ff432e45eedef9d15618b0b9af5378994bc46.zip
Add regression test for issue #17780
-rw-r--r--src/test/compile-fail/issue-17780.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/test/compile-fail/issue-17780.rs b/src/test/compile-fail/issue-17780.rs
new file mode 100644
index 00000000000..2072b2ee2d2
--- /dev/null
+++ b/src/test/compile-fail/issue-17780.rs
@@ -0,0 +1,50 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(unboxed_closures, overloaded_calls)]
+
+fn set(x: &mut uint) { *x = 5; }
+
+fn main() {
+    // By-ref captures
+    {
+        let mut x = 0u;
+        let _f = |&:| x = 42;
+        //~^ ERROR cannot assign to data in a free
+        // variable from an immutable unboxed closure
+
+        let mut y = 0u;
+        let _g = |&:| set(&mut y);
+        //~^ ERROR cannot borrow data mutably in a free
+        // variable from an immutable unboxed closure
+
+        let mut z = 0u;
+        let _h = |&mut:| { set(&mut z); |&:| z = 42; };
+        //~^ ERROR cannot assign to data in a
+        // free variable from an immutable unboxed closure
+    }
+    // By-value captures
+    {
+        let mut x = 0u;
+        let _f = move |&:| x = 42;
+        //~^ ERROR cannot assign to data in a free
+        // variable from an immutable unboxed closure
+
+        let mut y = 0u;
+        let _g = move |&:| set(&mut y);
+        //~^ ERROR cannot borrow data mutably in a free
+        // variable from an immutable unboxed closure
+
+        let mut z = 0u;
+        let _h = move |&mut:| { set(&mut z); move |&:| z = 42; };
+        //~^ ERROR cannot assign to data in a free
+        // variable from an immutable unboxed closure
+    }
+}