]> git.lizzy.rs Git - rust.git/blob - tests/ui/async-await/generator-not-future.rs
Rollup merge of #107114 - Erk-:add-absolute-note-to-path-join, r=m-ou-se
[rust.git] / tests / ui / async-await / generator-not-future.rs
1 // edition:2018
2 #![feature(generators, generator_trait)]
3
4 use std::future::Future;
5 use std::ops::Generator;
6
7 async fn async_fn() {}
8 fn returns_async_block() -> impl Future<Output = ()> {
9     async {}
10 }
11 fn returns_generator() -> impl Generator<(), Yield = (), Return = ()> {
12     || {
13         let _: () = yield ();
14     }
15 }
16
17 fn takes_future(_f: impl Future<Output = ()>) {}
18 fn takes_generator<ResumeTy>(_g: impl Generator<ResumeTy, Yield = (), Return = ()>) {}
19
20 fn main() {
21     // okay:
22     takes_future(async_fn());
23     takes_future(returns_async_block());
24     takes_future(async {});
25     takes_generator(returns_generator());
26     takes_generator(|| {
27         let _: () = yield ();
28     });
29
30     // async futures are not generators:
31     takes_generator(async_fn());
32     //~^ ERROR the trait bound
33     takes_generator(returns_async_block());
34     //~^ ERROR the trait bound
35     takes_generator(async {});
36     //~^ ERROR the trait bound
37
38     // generators are not futures:
39     takes_future(returns_generator());
40     //~^ ERROR is not a future
41     takes_future(|ctx| {
42         //~^ ERROR is not a future
43         ctx = yield ();
44     });
45 }