]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-65419/issue-65419-async-fn-resume-after-panic.rs
Fail fast if generator_kind is None
[rust.git] / src / test / ui / issues / issue-65419 / issue-65419-async-fn-resume-after-panic.rs
1 // issue 65419 - Attempting to run an async fn after completion mentions generators when it should
2 // be talking about `async fn`s instead. Should also test what happens when it panics.
3
4 // run-fail
5 // error-pattern: thread 'main' panicked at '`async fn` resumed after panicking'
6 // compile-flags: --edition 2018
7
8 #![feature(generators, generator_trait)]
9
10 use std::panic;
11
12 async fn foo() {
13     panic!();
14 }
15
16 fn main() {
17     let mut future = Box::pin(foo());
18     panic::catch_unwind(panic::AssertUnwindSafe(|| {
19         executor::block_on(future.as_mut());
20     }));
21
22     executor::block_on(future.as_mut());
23 }
24
25 mod executor {
26     use core::{
27         future::Future,
28         pin::Pin,
29         task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
30     };
31
32     pub fn block_on<F: Future>(mut future: F) -> F::Output {
33         let mut future = unsafe { Pin::new_unchecked(&mut future) };
34
35         static VTABLE: RawWakerVTable = RawWakerVTable::new(
36             |_| unimplemented!("clone"),
37             |_| unimplemented!("wake"),
38             |_| unimplemented!("wake_by_ref"),
39             |_| (),
40         );
41         let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
42         let mut context = Context::from_waker(&waker);
43
44         loop {
45             if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
46                 break val;
47             }
48         }
49     }
50 }