rust/tests/ui/async-await/issues/issue-53249.rs

48 lines
995 B
Rust
Raw Normal View History

// check-pass
2019-04-24 13:11:10 -05:00
// edition:2018
2019-08-01 20:45:58 -05:00
#![feature(arbitrary_self_types)]
2019-04-24 13:11:10 -05:00
use std::task::{self, Poll};
use std::future::Future;
use std::marker::Unpin;
use std::pin::Pin;
2021-08-22 09:20:58 -05:00
// This is a regression test for an ICE/unbounded recursion issue relating to async-await.
2019-04-24 13:11:10 -05:00
#[derive(Debug)]
#[must_use = "futures do nothing unless polled"]
pub struct Lazy<F> {
f: Option<F>
}
impl<F> Unpin for Lazy<F> {}
pub fn lazy<F, R>(f: F) -> Lazy<F>
where F: FnOnce(&mut task::Context) -> R,
{
Lazy { f: Some(f) }
}
impl<R, F> Future for Lazy<F>
where F: FnOnce(&mut task::Context) -> R,
{
type Output = R;
fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<R> {
Poll::Ready((self.f.take().unwrap())(cx))
}
}
async fn __receive<WantFn, Fut>(want: WantFn) -> ()
2019-05-28 13:46:13 -05:00
where Fut: Future<Output = ()>, WantFn: Fn(&Box<dyn Send + 'static>) -> Fut,
2019-04-24 13:11:10 -05:00
{
lazy(|_| ()).await;
2019-04-24 13:11:10 -05:00
}
pub fn basic_spawn_receive() {
async { __receive(|_| async { () }).await };
2019-04-24 13:11:10 -05:00
}
fn main() {}