about summary refs log tree commit diff
path: root/tests/ui/generator/clone-impl.rs
diff options
context:
space:
mode:
authorAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-05 09:13:28 +0100
committerAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-11 09:32:08 +0000
commitcf2dff2b1e3fa55fa5415d524200070d0d7aacfe (patch)
tree40a88d9a46aaf3e8870676eb2538378b75a263eb /tests/ui/generator/clone-impl.rs
parentca855e6e42787ecd062d81d53336fe6788ef51a9 (diff)
downloadrust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.tar.gz
rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.zip
Move /src/test to /tests
Diffstat (limited to 'tests/ui/generator/clone-impl.rs')
-rw-r--r--tests/ui/generator/clone-impl.rs73
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/ui/generator/clone-impl.rs b/tests/ui/generator/clone-impl.rs
new file mode 100644
index 00000000000..cbfd65a5309
--- /dev/null
+++ b/tests/ui/generator/clone-impl.rs
@@ -0,0 +1,73 @@
+// gate-test-generator_clone
+// Verifies that non-static generators can be cloned/copied if all their upvars and locals held
+// across awaits can be cloned/copied.
+
+#![feature(generators, generator_clone)]
+
+struct NonClone;
+
+fn main() {
+    let copyable: u32 = 123;
+    let clonable_0: Vec<u32> = Vec::new();
+    let clonable_1: Vec<u32> = Vec::new();
+    let non_clonable: NonClone = NonClone;
+
+    let gen_copy_0 = move || {
+        yield;
+        drop(copyable);
+    };
+    check_copy(&gen_copy_0);
+    check_clone(&gen_copy_0);
+    let gen_copy_1 = move || {
+        /*
+        let v = vec!['a'];
+        let n = NonClone;
+        drop(v);
+        drop(n);
+        */
+        yield;
+        let v = vec!['a'];
+        let n = NonClone;
+        drop(n);
+        drop(copyable);
+    };
+    check_copy(&gen_copy_1);
+    check_clone(&gen_copy_1);
+    let gen_clone_0 = move || {
+        let v = vec!['a'];
+        yield;
+        drop(v);
+        drop(clonable_0);
+    };
+    check_copy(&gen_clone_0);
+    //~^ ERROR the trait bound `Vec<u32>: Copy` is not satisfied
+    //~| ERROR the trait bound `Vec<char>: Copy` is not satisfied
+    check_clone(&gen_clone_0);
+    let gen_clone_1 = move || {
+        let v = vec!['a'];
+        /*
+        let n = NonClone;
+        drop(n);
+        */
+        yield;
+        let n = NonClone;
+        drop(n);
+        drop(v);
+        drop(clonable_1);
+    };
+    check_copy(&gen_clone_1);
+    //~^ ERROR the trait bound `Vec<u32>: Copy` is not satisfied
+    //~| ERROR the trait bound `Vec<char>: Copy` is not satisfied
+    check_clone(&gen_clone_1);
+    let gen_non_clone = move || {
+        yield;
+        drop(non_clonable);
+    };
+    check_copy(&gen_non_clone);
+    //~^ ERROR the trait bound `NonClone: Copy` is not satisfied
+    check_clone(&gen_non_clone);
+    //~^ ERROR the trait bound `NonClone: Clone` is not satisfied
+}
+
+fn check_copy<T: Copy>(_x: &T) {}
+fn check_clone<T: Clone>(_x: &T) {}