]> git.proxmox.com Git - rustc.git/blob - src/test/ui/generator/clone-impl.rs
Update upstream source from tag 'upstream/1.65.0+dfsg1'
[rustc.git] / src / test / ui / generator / clone-impl.rs
1 // gate-test-generator_clone
2 // Verifies that non-static generators can be cloned/copied if all their upvars and locals held
3 // across awaits can be cloned/copied.
4
5 #![feature(generators, generator_clone)]
6
7 struct NonClone;
8
9 fn main() {
10 let copyable: u32 = 123;
11 let clonable_0: Vec<u32> = Vec::new();
12 let clonable_1: Vec<u32> = Vec::new();
13 let non_clonable: NonClone = NonClone;
14
15 let gen_copy_0 = move || {
16 yield;
17 drop(copyable);
18 };
19 check_copy(&gen_copy_0);
20 check_clone(&gen_copy_0);
21 let gen_copy_1 = move || {
22 /*
23 let v = vec!['a'];
24 let n = NonClone;
25 drop(v);
26 drop(n);
27 */
28 yield;
29 let v = vec!['a'];
30 let n = NonClone;
31 drop(n);
32 drop(copyable);
33 };
34 check_copy(&gen_copy_1);
35 check_clone(&gen_copy_1);
36 let gen_clone_0 = move || {
37 let v = vec!['a'];
38 yield;
39 drop(v);
40 drop(clonable_0);
41 };
42 check_copy(&gen_clone_0);
43 //~^ ERROR the trait bound `Vec<u32>: Copy` is not satisfied
44 //~| ERROR the trait bound `Vec<char>: Copy` is not satisfied
45 check_clone(&gen_clone_0);
46 let gen_clone_1 = move || {
47 let v = vec!['a'];
48 /*
49 let n = NonClone;
50 drop(n);
51 */
52 yield;
53 let n = NonClone;
54 drop(n);
55 drop(v);
56 drop(clonable_1);
57 };
58 check_copy(&gen_clone_1);
59 //~^ ERROR the trait bound `Vec<u32>: Copy` is not satisfied
60 //~| ERROR the trait bound `Vec<char>: Copy` is not satisfied
61 check_clone(&gen_clone_1);
62 let gen_non_clone = move || {
63 yield;
64 drop(non_clonable);
65 };
66 check_copy(&gen_non_clone);
67 //~^ ERROR the trait bound `NonClone: Copy` is not satisfied
68 check_clone(&gen_non_clone);
69 //~^ ERROR the trait bound `NonClone: Clone` is not satisfied
70 }
71
72 fn check_copy<T: Copy>(_x: &T) {}
73 fn check_clone<T: Clone>(_x: &T) {}