Skip to content

Commit d9a1722

Browse files
canndrewcrlf0710
authored andcommitted
test async diagnostics for feature(generator_clone)
1 parent 62112f4 commit d9a1722

File tree

2 files changed

+242
-0
lines changed

2 files changed

+242
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// edition:2021
2+
// gate-test-generator_clone
3+
// Verifies that feature(generator_clone) doesn't allow async blocks to be cloned/copied.
4+
5+
#![feature(generators, generator_clone)]
6+
7+
use std::future::ready;
8+
9+
struct NonClone;
10+
11+
fn main() {
12+
let inner_non_clone = async {
13+
let non_clone = NonClone;
14+
let () = ready(()).await;
15+
drop(non_clone);
16+
};
17+
check_copy(&inner_non_clone);
18+
//~^ ERROR the trait bound `impl Future<Output = [async output]>: Copy` is not satisfied
19+
check_clone(&inner_non_clone);
20+
//~^ ERROR the trait bound `impl Future<Output = [async output]>: Clone` is not satisfied
21+
22+
let non_clone = NonClone;
23+
let outer_non_clone = async move {
24+
drop(non_clone);
25+
};
26+
check_copy(&outer_non_clone);
27+
//~^ ERROR the trait bound `impl Future<Output = [async output]>: Copy` is not satisfied
28+
check_clone(&outer_non_clone);
29+
//~^ ERROR the trait bound `impl Future<Output = [async output]>: Clone` is not satisfied
30+
31+
let maybe_copy_clone = async move {};
32+
check_copy(&maybe_copy_clone);
33+
//~^ ERROR the trait bound `impl Future<Output = [async output]>: Copy` is not satisfied
34+
check_clone(&maybe_copy_clone);
35+
//~^ ERROR the trait bound `impl Future<Output = [async output]>: Clone` is not satisfied
36+
37+
let inner_non_clone_fn = the_inner_non_clone_fn();
38+
check_copy(&inner_non_clone_fn);
39+
//~^ ERROR the trait bound `impl Future<Output = ()>: Copy` is not satisfied
40+
check_clone(&inner_non_clone_fn);
41+
//~^ ERROR the trait bound `impl Future<Output = ()>: Clone` is not satisfied
42+
43+
let outer_non_clone_fn = the_outer_non_clone_fn(NonClone);
44+
check_copy(&outer_non_clone_fn);
45+
//~^ ERROR the trait bound `impl Future<Output = ()>: Copy` is not satisfied
46+
check_clone(&outer_non_clone_fn);
47+
//~^ ERROR the trait bound `impl Future<Output = ()>: Clone` is not satisfied
48+
49+
let maybe_copy_clone_fn = the_maybe_copy_clone_fn();
50+
check_copy(&maybe_copy_clone_fn);
51+
//~^ ERROR the trait bound `impl Future<Output = ()>: Copy` is not satisfied
52+
check_clone(&maybe_copy_clone_fn);
53+
//~^ ERROR the trait bound `impl Future<Output = ()>: Clone` is not satisfied
54+
}
55+
56+
async fn the_inner_non_clone_fn() {
57+
let non_clone = NonClone;
58+
let () = ready(()).await;
59+
drop(non_clone);
60+
}
61+
62+
async fn the_outer_non_clone_fn(non_clone: NonClone) {
63+
let () = ready(()).await;
64+
drop(non_clone);
65+
}
66+
67+
async fn the_maybe_copy_clone_fn() {
68+
}
69+
70+
fn check_copy<T: Copy>(_x: &T) {}
71+
fn check_clone<T: Clone>(_x: &T) {}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
error[E0277]: the trait bound `impl Future<Output = [async output]>: Copy` is not satisfied
2+
--> $DIR/clone-impl-async.rs:17:16
3+
|
4+
LL | check_copy(&inner_non_clone);
5+
| ---------- ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `impl Future<Output = [async output]>`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
note: required by a bound in `check_copy`
10+
--> $DIR/clone-impl-async.rs:70: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 `impl Future<Output = [async output]>: Clone` is not satisfied
16+
--> $DIR/clone-impl-async.rs:19:17
17+
|
18+
LL | check_clone(&inner_non_clone);
19+
| ----------- ^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `impl Future<Output = [async output]>`
20+
| |
21+
| required by a bound introduced by this call
22+
|
23+
note: required by a bound in `check_clone`
24+
--> $DIR/clone-impl-async.rs:71:19
25+
|
26+
LL | fn check_clone<T: Clone>(_x: &T) {}
27+
| ^^^^^ required by this bound in `check_clone`
28+
29+
error[E0277]: the trait bound `impl Future<Output = [async output]>: Copy` is not satisfied
30+
--> $DIR/clone-impl-async.rs:26:16
31+
|
32+
LL | check_copy(&outer_non_clone);
33+
| ---------- ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `impl Future<Output = [async output]>`
34+
| |
35+
| required by a bound introduced by this call
36+
|
37+
note: required by a bound in `check_copy`
38+
--> $DIR/clone-impl-async.rs:70:18
39+
|
40+
LL | fn check_copy<T: Copy>(_x: &T) {}
41+
| ^^^^ required by this bound in `check_copy`
42+
43+
error[E0277]: the trait bound `impl Future<Output = [async output]>: Clone` is not satisfied
44+
--> $DIR/clone-impl-async.rs:28:17
45+
|
46+
LL | check_clone(&outer_non_clone);
47+
| ----------- ^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `impl Future<Output = [async output]>`
48+
| |
49+
| required by a bound introduced by this call
50+
|
51+
note: required by a bound in `check_clone`
52+
--> $DIR/clone-impl-async.rs:71:19
53+
|
54+
LL | fn check_clone<T: Clone>(_x: &T) {}
55+
| ^^^^^ required by this bound in `check_clone`
56+
57+
error[E0277]: the trait bound `impl Future<Output = [async output]>: Copy` is not satisfied
58+
--> $DIR/clone-impl-async.rs:32:16
59+
|
60+
LL | check_copy(&maybe_copy_clone);
61+
| ---------- ^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `impl Future<Output = [async output]>`
62+
| |
63+
| required by a bound introduced by this call
64+
|
65+
note: required by a bound in `check_copy`
66+
--> $DIR/clone-impl-async.rs:70:18
67+
|
68+
LL | fn check_copy<T: Copy>(_x: &T) {}
69+
| ^^^^ required by this bound in `check_copy`
70+
71+
error[E0277]: the trait bound `impl Future<Output = [async output]>: Clone` is not satisfied
72+
--> $DIR/clone-impl-async.rs:34:17
73+
|
74+
LL | check_clone(&maybe_copy_clone);
75+
| ----------- ^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `impl Future<Output = [async output]>`
76+
| |
77+
| required by a bound introduced by this call
78+
|
79+
note: required by a bound in `check_clone`
80+
--> $DIR/clone-impl-async.rs:71:19
81+
|
82+
LL | fn check_clone<T: Clone>(_x: &T) {}
83+
| ^^^^^ required by this bound in `check_clone`
84+
85+
error[E0277]: the trait bound `impl Future<Output = ()>: Copy` is not satisfied
86+
--> $DIR/clone-impl-async.rs:38:16
87+
|
88+
LL | check_copy(&inner_non_clone_fn);
89+
| ---------- ^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `impl Future<Output = ()>`
90+
| |
91+
| required by a bound introduced by this call
92+
|
93+
note: required by a bound in `check_copy`
94+
--> $DIR/clone-impl-async.rs:70:18
95+
|
96+
LL | fn check_copy<T: Copy>(_x: &T) {}
97+
| ^^^^ required by this bound in `check_copy`
98+
99+
error[E0277]: the trait bound `impl Future<Output = ()>: Clone` is not satisfied
100+
--> $DIR/clone-impl-async.rs:40:17
101+
|
102+
LL | check_clone(&inner_non_clone_fn);
103+
| ----------- ^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `impl Future<Output = ()>`
104+
| |
105+
| required by a bound introduced by this call
106+
|
107+
note: required by a bound in `check_clone`
108+
--> $DIR/clone-impl-async.rs:71:19
109+
|
110+
LL | fn check_clone<T: Clone>(_x: &T) {}
111+
| ^^^^^ required by this bound in `check_clone`
112+
113+
error[E0277]: the trait bound `impl Future<Output = ()>: Copy` is not satisfied
114+
--> $DIR/clone-impl-async.rs:44:16
115+
|
116+
LL | check_copy(&outer_non_clone_fn);
117+
| ---------- ^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `impl Future<Output = ()>`
118+
| |
119+
| required by a bound introduced by this call
120+
|
121+
note: required by a bound in `check_copy`
122+
--> $DIR/clone-impl-async.rs:70:18
123+
|
124+
LL | fn check_copy<T: Copy>(_x: &T) {}
125+
| ^^^^ required by this bound in `check_copy`
126+
127+
error[E0277]: the trait bound `impl Future<Output = ()>: Clone` is not satisfied
128+
--> $DIR/clone-impl-async.rs:46:17
129+
|
130+
LL | check_clone(&outer_non_clone_fn);
131+
| ----------- ^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `impl Future<Output = ()>`
132+
| |
133+
| required by a bound introduced by this call
134+
|
135+
note: required by a bound in `check_clone`
136+
--> $DIR/clone-impl-async.rs:71:19
137+
|
138+
LL | fn check_clone<T: Clone>(_x: &T) {}
139+
| ^^^^^ required by this bound in `check_clone`
140+
141+
error[E0277]: the trait bound `impl Future<Output = ()>: Copy` is not satisfied
142+
--> $DIR/clone-impl-async.rs:50:16
143+
|
144+
LL | check_copy(&maybe_copy_clone_fn);
145+
| ---------- ^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `impl Future<Output = ()>`
146+
| |
147+
| required by a bound introduced by this call
148+
|
149+
note: required by a bound in `check_copy`
150+
--> $DIR/clone-impl-async.rs:70:18
151+
|
152+
LL | fn check_copy<T: Copy>(_x: &T) {}
153+
| ^^^^ required by this bound in `check_copy`
154+
155+
error[E0277]: the trait bound `impl Future<Output = ()>: Clone` is not satisfied
156+
--> $DIR/clone-impl-async.rs:52:17
157+
|
158+
LL | check_clone(&maybe_copy_clone_fn);
159+
| ----------- ^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `impl Future<Output = ()>`
160+
| |
161+
| required by a bound introduced by this call
162+
|
163+
note: required by a bound in `check_clone`
164+
--> $DIR/clone-impl-async.rs:71:19
165+
|
166+
LL | fn check_clone<T: Clone>(_x: &T) {}
167+
| ^^^^^ required by this bound in `check_clone`
168+
169+
error: aborting due to 12 previous errors
170+
171+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)