Skip to content

Commit fa6dbcf

Browse files
canndrewcrlf0710
authored andcommitted
Add feature gate tests for generator_clone
1 parent 22f4bbb commit fa6dbcf

File tree

4 files changed

+284
-0
lines changed

4 files changed

+284
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// gate-test-generator_clone
2+
// Verifies that static generators cannot be cloned/copied.
3+
4+
#![feature(generators, generator_clone)]
5+
6+
fn main() {
7+
let gen = static move || {
8+
yield;
9+
};
10+
check_copy(&gen);
11+
//~^ ERROR Copy` is not satisfied
12+
check_clone(&gen);
13+
//~^ ERROR Clone` is not satisfied
14+
}
15+
16+
fn check_copy<T: Copy>(_x: &T) {}
17+
fn check_clone<T: Clone>(_x: &T) {}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error[E0277]: the trait bound `[static generator@$DIR/clone-impl-static.rs:7:15: 9:6]: Copy` is not satisfied
2+
--> $DIR/clone-impl-static.rs:10:16
3+
|
4+
LL | check_copy(&gen);
5+
| ---------- ^^^^ the trait `Copy` is not implemented for `[static generator@$DIR/clone-impl-static.rs:7:15: 9:6]`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
note: required by a bound in `check_copy`
10+
--> $DIR/clone-impl-static.rs:16:18
11+
|
12+
LL | fn check_copy<T: Copy>(_x: &T) {}
13+
| ^^^^ required by this bound in `check_copy`
14+
15+
error[E0277]: the trait bound `[static generator@$DIR/clone-impl-static.rs:7:15: 9:6]: Clone` is not satisfied
16+
--> $DIR/clone-impl-static.rs:12:17
17+
|
18+
LL | check_clone(&gen);
19+
| ----------- ^^^^ the trait `Clone` is not implemented for `[static generator@$DIR/clone-impl-static.rs:7:15: 9:6]`
20+
| |
21+
| required by a bound introduced by this call
22+
|
23+
note: required by a bound in `check_clone`
24+
--> $DIR/clone-impl-static.rs:17:19
25+
|
26+
LL | fn check_clone<T: Clone>(_x: &T) {}
27+
| ^^^^^ required by this bound in `check_clone`
28+
29+
error: aborting due to 2 previous errors
30+
31+
For more information about this error, try `rustc --explain E0277`.

src/test/ui/generator/clone-impl.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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) {}
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
error[E0277]: the trait bound `Vec<u32>: Copy` is not satisfied in `[generator@$DIR/clone-impl.rs:36:23: 41:6]`
2+
--> $DIR/clone-impl.rs:42:5
3+
|
4+
LL | let gen_clone_0 = move || {
5+
| _______________________-
6+
LL | | let v = vec!['a'];
7+
LL | | yield;
8+
LL | | drop(v);
9+
LL | | drop(clonable_0);
10+
LL | | };
11+
| |_____- within this `[generator@$DIR/clone-impl.rs:36:23: 41:6]`
12+
LL | check_copy(&gen_clone_0);
13+
| ^^^^^^^^^^ within `[generator@$DIR/clone-impl.rs:36:23: 41:6]`, the trait `Copy` is not implemented for `Vec<u32>`
14+
|
15+
note: captured value does not implement `Copy`
16+
--> $DIR/clone-impl.rs:40:14
17+
|
18+
LL | drop(clonable_0);
19+
| ^^^^^^^^^^ has type `Vec<u32>` which does not implement `Copy`
20+
note: required by a bound in `check_copy`
21+
--> $DIR/clone-impl.rs:72:18
22+
|
23+
LL | fn check_copy<T: Copy>(_x: &T) {}
24+
| ^^^^ required by this bound in `check_copy`
25+
26+
error[E0277]: the trait bound `Vec<char>: Copy` is not satisfied in `[generator@$DIR/clone-impl.rs:36:23: 41:6]`
27+
--> $DIR/clone-impl.rs:42:5
28+
|
29+
LL | let gen_clone_0 = move || {
30+
| _______________________-
31+
LL | | let v = vec!['a'];
32+
LL | | yield;
33+
LL | | drop(v);
34+
LL | | drop(clonable_0);
35+
LL | | };
36+
| |_____- within this `[generator@$DIR/clone-impl.rs:36:23: 41:6]`
37+
LL | check_copy(&gen_clone_0);
38+
| ^^^^^^^^^^ within `[generator@$DIR/clone-impl.rs:36:23: 41:6]`, the trait `Copy` is not implemented for `Vec<char>`
39+
|
40+
note: generator does not implement `Copy` as this value is used across a yield
41+
--> $DIR/clone-impl.rs:38:9
42+
|
43+
LL | let v = vec!['a'];
44+
| - has type `Vec<char>` which does not implement `Copy`
45+
LL | yield;
46+
| ^^^^^ yield occurs here, with `v` maybe used later
47+
...
48+
LL | };
49+
| - `v` is later dropped here
50+
note: required by a bound in `check_copy`
51+
--> $DIR/clone-impl.rs:72:18
52+
|
53+
LL | fn check_copy<T: Copy>(_x: &T) {}
54+
| ^^^^ required by this bound in `check_copy`
55+
56+
error[E0277]: the trait bound `Vec<u32>: Copy` is not satisfied in `[generator@$DIR/clone-impl.rs:46:23: 57:6]`
57+
--> $DIR/clone-impl.rs:58:5
58+
|
59+
LL | let gen_clone_1 = move || {
60+
| _______________________-
61+
LL | | let v = vec!['a'];
62+
LL | | /*
63+
LL | | let n = NonClone;
64+
... |
65+
LL | | drop(clonable_1);
66+
LL | | };
67+
| |_____- within this `[generator@$DIR/clone-impl.rs:46:23: 57:6]`
68+
LL | check_copy(&gen_clone_1);
69+
| ^^^^^^^^^^ within `[generator@$DIR/clone-impl.rs:46:23: 57:6]`, the trait `Copy` is not implemented for `Vec<u32>`
70+
|
71+
note: captured value does not implement `Copy`
72+
--> $DIR/clone-impl.rs:56:14
73+
|
74+
LL | drop(clonable_1);
75+
| ^^^^^^^^^^ has type `Vec<u32>` which does not implement `Copy`
76+
note: required by a bound in `check_copy`
77+
--> $DIR/clone-impl.rs:72:18
78+
|
79+
LL | fn check_copy<T: Copy>(_x: &T) {}
80+
| ^^^^ required by this bound in `check_copy`
81+
82+
error[E0277]: the trait bound `Vec<char>: Copy` is not satisfied in `[generator@$DIR/clone-impl.rs:46:23: 57:6]`
83+
--> $DIR/clone-impl.rs:58:5
84+
|
85+
LL | let gen_clone_1 = move || {
86+
| _______________________-
87+
LL | | let v = vec!['a'];
88+
LL | | /*
89+
LL | | let n = NonClone;
90+
... |
91+
LL | | drop(clonable_1);
92+
LL | | };
93+
| |_____- within this `[generator@$DIR/clone-impl.rs:46:23: 57:6]`
94+
LL | check_copy(&gen_clone_1);
95+
| ^^^^^^^^^^ within `[generator@$DIR/clone-impl.rs:46:23: 57:6]`, the trait `Copy` is not implemented for `Vec<char>`
96+
|
97+
note: generator does not implement `Copy` as this value is used across a yield
98+
--> $DIR/clone-impl.rs:52:9
99+
|
100+
LL | let v = vec!['a'];
101+
| - has type `Vec<char>` which does not implement `Copy`
102+
...
103+
LL | yield;
104+
| ^^^^^ yield occurs here, with `v` maybe used later
105+
...
106+
LL | };
107+
| - `v` is later dropped here
108+
note: required by a bound in `check_copy`
109+
--> $DIR/clone-impl.rs:72:18
110+
|
111+
LL | fn check_copy<T: Copy>(_x: &T) {}
112+
| ^^^^ required by this bound in `check_copy`
113+
114+
error[E0277]: the trait bound `NonClone: Copy` is not satisfied in `[generator@$DIR/clone-impl.rs:62:25: 65:6]`
115+
--> $DIR/clone-impl.rs:66:5
116+
|
117+
LL | let gen_non_clone = move || {
118+
| _________________________-
119+
LL | | yield;
120+
LL | | drop(non_clonable);
121+
LL | | };
122+
| |_____- within this `[generator@$DIR/clone-impl.rs:62:25: 65:6]`
123+
LL | check_copy(&gen_non_clone);
124+
| ^^^^^^^^^^ within `[generator@$DIR/clone-impl.rs:62:25: 65:6]`, the trait `Copy` is not implemented for `NonClone`
125+
|
126+
note: captured value does not implement `Copy`
127+
--> $DIR/clone-impl.rs:64:14
128+
|
129+
LL | drop(non_clonable);
130+
| ^^^^^^^^^^^^ has type `NonClone` which does not implement `Copy`
131+
note: required by a bound in `check_copy`
132+
--> $DIR/clone-impl.rs:72:18
133+
|
134+
LL | fn check_copy<T: Copy>(_x: &T) {}
135+
| ^^^^ required by this bound in `check_copy`
136+
137+
error[E0277]: the trait bound `NonClone: Clone` is not satisfied in `[generator@$DIR/clone-impl.rs:62:25: 65:6]`
138+
--> $DIR/clone-impl.rs:68:5
139+
|
140+
LL | let gen_non_clone = move || {
141+
| _________________________-
142+
LL | | yield;
143+
LL | | drop(non_clonable);
144+
LL | | };
145+
| |_____- within this `[generator@$DIR/clone-impl.rs:62:25: 65:6]`
146+
...
147+
LL | check_clone(&gen_non_clone);
148+
| ^^^^^^^^^^^ within `[generator@$DIR/clone-impl.rs:62:25: 65:6]`, the trait `Clone` is not implemented for `NonClone`
149+
|
150+
note: captured value does not implement `Clone`
151+
--> $DIR/clone-impl.rs:64:14
152+
|
153+
LL | drop(non_clonable);
154+
| ^^^^^^^^^^^^ has type `NonClone` which does not implement `Clone`
155+
note: required by a bound in `check_clone`
156+
--> $DIR/clone-impl.rs:73:19
157+
|
158+
LL | fn check_clone<T: Clone>(_x: &T) {}
159+
| ^^^^^ required by this bound in `check_clone`
160+
161+
error: aborting due to 6 previous errors
162+
163+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)