2023-10-19 21:46:28 +00:00
|
|
|
//! Tests that panics inside a coroutine will correctly drop the initial resume argument.
|
2020-02-04 12:18:29 +00:00
|
|
|
|
|
|
|
//@ run-pass
|
2021-12-03 15:32:51 +00:00
|
|
|
//@ needs-unwind
|
2020-02-04 12:18:29 +00:00
|
|
|
|
2024-04-11 13:15:34 +00:00
|
|
|
#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
|
2020-02-04 12:18:29 +00:00
|
|
|
|
2023-10-19 16:06:43 +00:00
|
|
|
use std::ops::Coroutine;
|
2020-02-04 12:18:29 +00:00
|
|
|
use std::panic::{catch_unwind, AssertUnwindSafe};
|
|
|
|
use std::pin::Pin;
|
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
|
|
|
|
|
|
static DROP: AtomicUsize = AtomicUsize::new(0);
|
|
|
|
|
|
|
|
struct Dropper {}
|
|
|
|
|
|
|
|
impl Drop for Dropper {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
DROP.fetch_add(1, Ordering::SeqCst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2024-04-11 13:15:34 +00:00
|
|
|
let mut gen = #[coroutine] |_arg| {
|
2020-02-04 12:18:29 +00:00
|
|
|
if true {
|
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
yield ();
|
|
|
|
};
|
|
|
|
let mut gen = Pin::new(&mut gen);
|
|
|
|
|
|
|
|
assert_eq!(DROP.load(Ordering::Acquire), 0);
|
|
|
|
let res = catch_unwind(AssertUnwindSafe(|| gen.as_mut().resume(Dropper {})));
|
|
|
|
assert!(res.is_err());
|
|
|
|
assert_eq!(DROP.load(Ordering::Acquire), 1);
|
|
|
|
}
|