1 // issue 65419 - Attempting to run an async fn after completion mentions generators when it should
2 // be talking about `async fn`s instead.
3
4 // run-fail
5 // error-pattern: thread 'main' panicked at '`async fn` resumed after completion'
6 // edition:2018
7 // ignore-wasm no panic or subprocess support
8 // ignore-emscripten no panic or subprocess support
9
10 #![feature(generators, generator_trait)]
11
foo()12 async fn foo() {
13 }
14
main()15 fn main() {
16 let mut future = Box::pin(foo());
17 executor::block_on(future.as_mut());
18 executor::block_on(future.as_mut());
19 }
20
21 mod executor {
22 use core::{
23 future::Future,
24 pin::Pin,
25 task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
26 };
27
block_on<F: Future>(mut future: F) -> F::Output28 pub fn block_on<F: Future>(mut future: F) -> F::Output {
29 let mut future = unsafe { Pin::new_unchecked(&mut future) };
30
31 static VTABLE: RawWakerVTable = RawWakerVTable::new(
32 |_| unimplemented!("clone"),
33 |_| unimplemented!("wake"),
34 |_| unimplemented!("wake_by_ref"),
35 |_| (),
36 );
37 let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
38 let mut context = Context::from_waker(&waker);
39
40 loop {
41 if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
42 break val;
43 }
44 }
45 }
46 }
47