2019-11-25 06:58:40 -06:00
|
|
|
// issue 65419 - Attempting to run an async fn after completion mentions generators when it should
|
|
|
|
// be talking about `async fn`s instead. Should also test what happens when it panics.
|
|
|
|
|
|
|
|
// run-fail
|
2021-12-03 09:32:51 -06:00
|
|
|
// needs-unwind
|
2019-11-25 20:40:01 -06:00
|
|
|
// error-pattern: thread 'main' panicked at '`async fn` resumed after panicking'
|
2019-11-28 02:24:19 -06:00
|
|
|
// edition:2018
|
2019-11-29 09:37:46 -06:00
|
|
|
// ignore-wasm no panic or subprocess support
|
2019-11-25 06:58:40 -06:00
|
|
|
|
|
|
|
#![feature(generators, generator_trait)]
|
|
|
|
|
|
|
|
use std::panic;
|
|
|
|
|
|
|
|
async fn foo() {
|
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut future = Box::pin(foo());
|
|
|
|
panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
|
|
|
executor::block_on(future.as_mut());
|
|
|
|
}));
|
|
|
|
|
|
|
|
executor::block_on(future.as_mut());
|
|
|
|
}
|
|
|
|
|
|
|
|
mod executor {
|
|
|
|
use core::{
|
|
|
|
future::Future,
|
|
|
|
pin::Pin,
|
|
|
|
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn block_on<F: Future>(mut future: F) -> F::Output {
|
|
|
|
let mut future = unsafe { Pin::new_unchecked(&mut future) };
|
|
|
|
|
|
|
|
static VTABLE: RawWakerVTable = RawWakerVTable::new(
|
|
|
|
|_| unimplemented!("clone"),
|
|
|
|
|_| unimplemented!("wake"),
|
|
|
|
|_| unimplemented!("wake_by_ref"),
|
|
|
|
|_| (),
|
|
|
|
);
|
|
|
|
let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
|
|
|
|
let mut context = Context::from_waker(&waker);
|
|
|
|
|
|
|
|
loop {
|
|
|
|
if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
|
|
|
|
break val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|