about summary refs log tree commit diff
path: root/src/test/compile-fail
diff options
context:
space:
mode:
authorBrian Koropoff <bkoropoff@gmail.com>2014-10-03 00:57:21 -0700
committerBrian Koropoff <bkoropoff@gmail.com>2014-10-03 00:57:21 -0700
commit521ca31071c01b21de40ce3477a81972103b3db9 (patch)
treef1958f8c179b8b1ec6feb74da8645e23a620ea6c /src/test/compile-fail
parent39344c2d7ec6fdacb7085aefda3e440891e0855a (diff)
downloadrust-521ca31071c01b21de40ce3477a81972103b3db9.tar.gz
rust-521ca31071c01b21de40ce3477a81972103b3db9.zip
Add some more test coverage of by-ref unboxed closures
Diffstat (limited to 'src/test/compile-fail')
-rw-r--r--src/test/compile-fail/unboxed-closure-region.rs20
-rw-r--r--src/test/compile-fail/unboxed-closures-borrow-conflict.rs20
2 files changed, 40 insertions, 0 deletions
diff --git a/src/test/compile-fail/unboxed-closure-region.rs b/src/test/compile-fail/unboxed-closure-region.rs
new file mode 100644
index 00000000000..2a71aeaca5f
--- /dev/null
+++ b/src/test/compile-fail/unboxed-closure-region.rs
@@ -0,0 +1,20 @@
+// 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)]
+
+// Test that an unboxed closure that captures a free variable by
+// reference cannot escape the region of that variable.
+fn main() {
+    let _f = {
+        let x = 0u;
+        |:| x //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements
+    };
+}
diff --git a/src/test/compile-fail/unboxed-closures-borrow-conflict.rs b/src/test/compile-fail/unboxed-closures-borrow-conflict.rs
new file mode 100644
index 00000000000..baf7f3f5e58
--- /dev/null
+++ b/src/test/compile-fail/unboxed-closures-borrow-conflict.rs
@@ -0,0 +1,20 @@
+// 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)]
+
+// Test that an unboxed closure that mutates a free variable will
+// cause borrow conflicts.
+
+fn main() {
+    let mut x = 0u;
+    let f = |:| x += 1;
+    let _y = x; //~ ERROR cannot use `x` because it was mutably borrowed
+}