]> git.proxmox.com Git - rustc.git/blob - src/test/ui/async-await/issues/issue-65419/issue-65419-async-fn-resume-after-panic.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / test / ui / async-await / 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 // 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
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 }