2019-11-04 00:00:00 +00:00
|
|
|
// check-pass
|
2019-04-24 18:11:10 +00:00
|
|
|
// edition:2018
|
|
|
|
|
2019-08-02 01:45:58 +00:00
|
|
|
#![feature(arbitrary_self_types)]
|
2019-04-24 18:11:10 +00:00
|
|
|
|
|
|
|
use std::task::{self, Poll};
|
|
|
|
use std::future::Future;
|
|
|
|
use std::marker::Unpin;
|
|
|
|
use std::pin::Pin;
|
|
|
|
|
2021-08-22 14:20:58 +00:00
|
|
|
// This is a regression test for an ICE/unbounded recursion issue relating to async-await.
|
2019-04-24 18:11:10 +00: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 18:46:13 +00:00
|
|
|
where Fut: Future<Output = ()>, WantFn: Fn(&Box<dyn Send + 'static>) -> Fut,
|
2019-04-24 18:11:10 +00:00
|
|
|
{
|
2019-07-03 22:25:14 +00:00
|
|
|
lazy(|_| ()).await;
|
2019-04-24 18:11:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn basic_spawn_receive() {
|
2019-07-03 22:25:14 +00:00
|
|
|
async { __receive(|_| async { () }).await };
|
2019-04-24 18:11:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|