Squash
This commit is contained in:
parent
96ad8e5fbc
commit
ec41fda58b
13 changed files with 192 additions and 33 deletions
|
|
@ -0,0 +1,44 @@
|
|||
// issue 65419 - Attempting to run an async fn after completion mentions generators when it should
|
||||
// be talking about `async fn`s instead.
|
||||
|
||||
// run-fail
|
||||
// error-pattern: thread 'main' panicked at '`async fn` resumed after completion'
|
||||
// compile-flags: --edition 2018
|
||||
|
||||
#![feature(generators, generator_trait)]
|
||||
|
||||
async fn foo() {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut future = Box::pin(foo());
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
// 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
|
||||
// error-pattern: thread 'main' panicked at '`async fn` resumed after panic'
|
||||
// compile-flags: --edition 2018
|
||||
|
||||
#![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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
// issue 65419 - Attempting to run an `async fn` after completion mentions generators when it should
|
||||
// be talking about `async fn`s instead. Regression test added to make sure generators still
|
||||
// panic when resumed after completion.
|
||||
|
||||
// run-fail
|
||||
// error-pattern:generator resumed after completion
|
||||
|
||||
#![feature(generators, generator_trait)]
|
||||
|
||||
use std::{
|
||||
ops::Generator,
|
||||
pin::Pin,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
let mut g = || {
|
||||
yield;
|
||||
};
|
||||
Pin::new(&mut g).resume(); // Yields once.
|
||||
Pin::new(&mut g).resume(); // Completes here.
|
||||
Pin::new(&mut g).resume(); // Panics here.
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue