]> git.lizzy.rs Git - rust.git/blob - src/test/ui/async-await/issues/issue-53249.rs
Rollup merge of #71627 - ldm0:autoderefarg, r=Dylan-DPC
[rust.git] / src / test / ui / async-await / issues / issue-53249.rs
1 // check-pass
2 // edition:2018
3
4 #![feature(arbitrary_self_types)]
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<dyn Send + 'static>) -> Fut,
39 {
40     lazy(|_| ()).await;
41 }
42
43 pub fn basic_spawn_receive() {
44     async { __receive(|_| async { () }).await };
45 }
46
47 fn main() {}