]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issue-53249.rs
Auto merge of #60065 - QuietMisdreavus:async-move-doctests, r=ollie27
[rust.git] / src / test / ui / issue-53249.rs
1 // compile-pass
2 // edition:2018
3
4 #![feature(arbitrary_self_types, async_await, await_macro)]
5
6 use std::task::{self, Poll};
7 use std::future::Future;
8 use std::marker::Unpin;
9 use std::pin::Pin;
10
11 // This is a regression test for a ICE/unbounded recursion issue relating to async-await.
12
13 #[derive(Debug)]
14 #[must_use = "futures do nothing unless polled"]
15 pub struct Lazy<F> {
16     f: Option<F>
17 }
18
19 impl<F> Unpin for Lazy<F> {}
20
21 pub fn lazy<F, R>(f: F) -> Lazy<F>
22     where F: FnOnce(&mut task::Context) -> R,
23 {
24     Lazy { f: Some(f) }
25 }
26
27 impl<R, F> Future for Lazy<F>
28     where F: FnOnce(&mut task::Context) -> R,
29 {
30     type Output = R;
31
32     fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<R> {
33         Poll::Ready((self.f.take().unwrap())(cx))
34     }
35 }
36
37 async fn __receive<WantFn, Fut>(want: WantFn) -> ()
38     where Fut: Future<Output = ()>, WantFn: Fn(&Box<Send + 'static>) -> Fut,
39 {
40     await!(lazy(|_| ()));
41 }
42
43 pub fn basic_spawn_receive() {
44     async { await!(__receive(|_| async { () })) };
45 }
46
47 fn main() {}