]>
Commit | Line | Data |
---|---|---|
60c5eb7d XL |
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 | |
a2a8927a | 5 | // needs-unwind |
60c5eb7d XL |
6 | // error-pattern: thread 'main' panicked at '`async fn` resumed after panicking' |
7 | // edition:2018 | |
8 | // ignore-wasm no panic or subprocess support | |
60c5eb7d XL |
9 | |
10 | #![feature(generators, generator_trait)] | |
11 | ||
12 | use std::panic; | |
13 | ||
14 | async fn foo() { | |
15 | panic!(); | |
16 | } | |
17 | ||
18 | fn main() { | |
19 | let mut future = Box::pin(foo()); | |
20 | panic::catch_unwind(panic::AssertUnwindSafe(|| { | |
21 | executor::block_on(future.as_mut()); | |
22 | })); | |
23 | ||
24 | executor::block_on(future.as_mut()); | |
25 | } | |
26 | ||
27 | mod executor { | |
28 | use core::{ | |
29 | future::Future, | |
30 | pin::Pin, | |
31 | task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, | |
32 | }; | |
33 | ||
34 | pub fn block_on<F: Future>(mut future: F) -> F::Output { | |
35 | let mut future = unsafe { Pin::new_unchecked(&mut future) }; | |
36 | ||
37 | static VTABLE: RawWakerVTable = RawWakerVTable::new( | |
38 | |_| unimplemented!("clone"), | |
39 | |_| unimplemented!("wake"), | |
40 | |_| unimplemented!("wake_by_ref"), | |
41 | |_| (), | |
42 | ); | |
43 | let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) }; | |
44 | let mut context = Context::from_waker(&waker); | |
45 | ||
46 | loop { | |
47 | if let Poll::Ready(val) = future.as_mut().poll(&mut context) { | |
48 | break val; | |
49 | } | |
50 | } | |
51 | } | |
52 | } |