summary refs log tree commit diff
path: root/src/test/compile-fail
diff options
context:
space:
mode:
authorscalexm <martin.alex32@hotmail.fr>2017-09-13 22:40:48 +0200
committerscalexm <martin.alex32@hotmail.fr>2017-09-20 20:43:41 +0200
commitf7964aebe516bc7e4f06f7128ebb39ad5576a1a7 (patch)
treefb903110af5ee4e9a3437f70b2cd9b7a7466ef6d /src/test/compile-fail
parent01c65cb15ac57bfdc91613a4f6032ecc76c402a3 (diff)
downloadrust-f7964aebe516bc7e4f06f7128ebb39ad5576a1a7.tar.gz
rust-f7964aebe516bc7e4f06f7128ebb39ad5576a1a7.zip
Implement `Copy`/`Clone` for closures
Diffstat (limited to 'src/test/compile-fail')
-rw-r--r--src/test/compile-fail/feature-gate-clone-closures.rs21
-rw-r--r--src/test/compile-fail/feature-gate-copy-closures.rs19
-rw-r--r--src/test/compile-fail/not-clone-closure.rs24
-rw-r--r--src/test/compile-fail/not-copy-closure.rs24
4 files changed, 88 insertions, 0 deletions
diff --git a/src/test/compile-fail/feature-gate-clone-closures.rs b/src/test/compile-fail/feature-gate-clone-closures.rs
new file mode 100644
index 00000000000..a15153ea7bf
--- /dev/null
+++ b/src/test/compile-fail/feature-gate-clone-closures.rs
@@ -0,0 +1,21 @@
+// Copyright 2017 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.
+
+#[derive(Clone)]
+struct S(i32);
+
+fn main() {
+    let a = S(5);
+    let hello = move || {
+        println!("Hello {}", a.0);
+    };
+
+    let hello = hello.clone(); //~ ERROR no method named `clone` found for type
+}
diff --git a/src/test/compile-fail/feature-gate-copy-closures.rs b/src/test/compile-fail/feature-gate-copy-closures.rs
new file mode 100644
index 00000000000..b11b09eb9fd
--- /dev/null
+++ b/src/test/compile-fail/feature-gate-copy-closures.rs
@@ -0,0 +1,19 @@
+// Copyright 2017 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.
+
+fn main() {
+    let a = 5;
+    let hello = || {
+        println!("Hello {}", a);
+    };
+
+    let b = hello;
+    let c = hello; //~ ERROR use of moved value: `hello` [E0382]
+}
diff --git a/src/test/compile-fail/not-clone-closure.rs b/src/test/compile-fail/not-clone-closure.rs
new file mode 100644
index 00000000000..2a30dc4fdd4
--- /dev/null
+++ b/src/test/compile-fail/not-clone-closure.rs
@@ -0,0 +1,24 @@
+// Copyright 2017 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.
+
+// Check that closures do not implement `Clone` if their environment is not `Clone`.
+
+#![feature(clone_closures)]
+
+struct S(i32);
+
+fn main() {
+    let a = S(5);
+    let hello = move || {
+        println!("Hello {}", a.0);
+    };
+
+    let hello = hello.clone(); //~ ERROR the trait bound `S: std::clone::Clone` is not satisfied
+}
diff --git a/src/test/compile-fail/not-copy-closure.rs b/src/test/compile-fail/not-copy-closure.rs
new file mode 100644
index 00000000000..271e6d5fc90
--- /dev/null
+++ b/src/test/compile-fail/not-copy-closure.rs
@@ -0,0 +1,24 @@
+// Copyright 2017 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.
+
+// Check that closures do not implement `Copy` if their environment is not `Copy`.
+
+#![feature(copy_closures)]
+#![feature(clone_closures)]
+
+fn main() {
+    let mut a = 5;
+    let hello = || {
+        a += 1;
+    };
+
+    let b = hello;
+    let c = hello; //~ ERROR use of moved value: `hello` [E0382]
+}