2024-02-16 20:02:50 +00:00
|
|
|
//@ run-pass
|
|
|
|
//@ needs-unwind
|
2018-09-06 12:41:12 +00:00
|
|
|
|
2017-10-23 03:01:00 +00:00
|
|
|
|
2023-10-19 21:46:28 +00:00
|
|
|
#![feature(coroutines, coroutine_trait)]
|
2017-07-07 23:12:44 +00:00
|
|
|
|
2023-10-19 16:06:43 +00:00
|
|
|
use std::ops::Coroutine;
|
2017-07-07 23:12:44 +00:00
|
|
|
use std::panic;
|
2018-10-04 18:49:38 +00:00
|
|
|
use std::pin::Pin;
|
2019-01-26 16:14:49 +00:00
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
2017-07-07 23:12:44 +00:00
|
|
|
|
2019-01-26 16:14:49 +00:00
|
|
|
static A: AtomicUsize = AtomicUsize::new(0);
|
2017-07-07 23:12:44 +00:00
|
|
|
|
|
|
|
struct B;
|
|
|
|
|
|
|
|
impl Drop for B {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
A.fetch_add(1, Ordering::SeqCst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-09 20:56:19 +00:00
|
|
|
fn bool_true() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2017-07-07 23:12:44 +00:00
|
|
|
fn main() {
|
|
|
|
let b = B;
|
|
|
|
let mut foo = || {
|
2017-08-09 20:56:19 +00:00
|
|
|
if bool_true() {
|
2017-07-07 23:12:44 +00:00
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
drop(b);
|
|
|
|
yield;
|
|
|
|
};
|
|
|
|
|
|
|
|
assert_eq!(A.load(Ordering::SeqCst), 0);
|
|
|
|
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
2020-01-25 19:03:10 +00:00
|
|
|
Pin::new(&mut foo).resume(())
|
2017-07-07 23:12:44 +00:00
|
|
|
}));
|
|
|
|
assert!(res.is_err());
|
|
|
|
assert_eq!(A.load(Ordering::SeqCst), 1);
|
|
|
|
|
|
|
|
let mut foo = || {
|
2017-08-09 20:56:19 +00:00
|
|
|
if bool_true() {
|
2017-07-07 23:12:44 +00:00
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
drop(B);
|
|
|
|
yield;
|
|
|
|
};
|
|
|
|
|
|
|
|
assert_eq!(A.load(Ordering::SeqCst), 1);
|
|
|
|
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
2020-01-25 19:03:10 +00:00
|
|
|
Pin::new(&mut foo).resume(())
|
2017-07-07 23:12:44 +00:00
|
|
|
}));
|
|
|
|
assert!(res.is_err());
|
|
|
|
assert_eq!(A.load(Ordering::SeqCst), 1);
|
|
|
|
}
|