]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generator/clone-impl-async.rs
Auto merge of #102655 - joboet:windows_tls_opt, r=ChrisDenton
[rust.git] / src / test / ui / generator / clone-impl-async.rs
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 = ()>: Copy` is not satisfied
19     check_clone(&inner_non_clone);
20     //~^ ERROR the trait bound `impl Future<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 = ()>: Copy` is not satisfied
28     check_clone(&outer_non_clone);
29     //~^ ERROR the trait bound `impl Future<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 = ()>: Copy` is not satisfied
34     check_clone(&maybe_copy_clone);
35     //~^ ERROR the trait bound `impl Future<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) {}