]> git.lizzy.rs Git - rust.git/blob - tests/ui/async-await/issue-98634.rs
Rollup merge of #106946 - dtolnay:hashlinecolumn, r=m-ou-se
[rust.git] / tests / ui / async-await / issue-98634.rs
1 // edition: 2021
2
3 use std::{
4     future::Future,
5     pin::Pin,
6     task::{Context, Poll, Waker},
7 };
8
9 pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> {
10     pub callback: F,
11 }
12
13 impl<F> Future for StructAsync<F>
14 where
15     F: Fn() -> Pin<Box<dyn Future<Output = ()>>>,
16 {
17     type Output = ();
18
19     fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
20         Poll::Pending
21     }
22 }
23
24 async fn callback() {}
25
26 struct Runtime;
27
28 fn waker() -> &'static Waker {
29     todo!()
30 }
31
32 impl Runtime {
33     #[track_caller]
34     pub fn block_on<F: Future>(&self, mut future: F) -> F::Output {
35         loop {
36             unsafe {
37                 Pin::new_unchecked(&mut future).poll(&mut Context::from_waker(waker()));
38             }
39         }
40     }
41 }
42
43 fn main() {
44     Runtime.block_on(async {
45         StructAsync { callback }.await;
46         //~^ ERROR expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
47         //~| ERROR expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
48         //~| ERROR expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
49     });
50 }