2018-09-06 07:41:12 -05:00
|
|
|
// run-pass
|
|
|
|
|
2017-10-22 22:01:00 -05:00
|
|
|
// ignore-wasm32-bare compiled as panic=abort by default
|
|
|
|
|
2017-07-07 18:12:44 -05:00
|
|
|
#![feature(generators, generator_trait)]
|
|
|
|
|
|
|
|
use std::ops::Generator;
|
|
|
|
use std::panic;
|
2019-01-26 10:14:49 -06:00
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
2017-07-07 18:12:44 -05:00
|
|
|
|
2019-01-26 10:14:49 -06:00
|
|
|
static A: AtomicUsize = AtomicUsize::new(0);
|
2017-07-07 18:12:44 -05:00
|
|
|
|
|
|
|
struct B;
|
|
|
|
|
|
|
|
impl Drop for B {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
A.fetch_add(1, Ordering::SeqCst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-09 15:56:19 -05:00
|
|
|
fn bool_true() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2017-07-07 18:12:44 -05:00
|
|
|
fn main() {
|
|
|
|
let b = B;
|
|
|
|
let mut foo = || {
|
2017-08-09 15:56:19 -05:00
|
|
|
if bool_true() {
|
2017-07-07 18:12:44 -05:00
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
drop(b);
|
|
|
|
yield;
|
|
|
|
};
|
|
|
|
|
|
|
|
assert_eq!(A.load(Ordering::SeqCst), 0);
|
|
|
|
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
2018-03-19 18:48:41 -05:00
|
|
|
unsafe { foo.resume() }
|
2017-07-07 18:12:44 -05:00
|
|
|
}));
|
|
|
|
assert!(res.is_err());
|
|
|
|
assert_eq!(A.load(Ordering::SeqCst), 1);
|
|
|
|
|
|
|
|
let mut foo = || {
|
2017-08-09 15:56:19 -05:00
|
|
|
if bool_true() {
|
2017-07-07 18:12:44 -05:00
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
drop(B);
|
|
|
|
yield;
|
|
|
|
};
|
|
|
|
|
|
|
|
assert_eq!(A.load(Ordering::SeqCst), 1);
|
|
|
|
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
2018-03-19 18:48:41 -05:00
|
|
|
unsafe { foo.resume() }
|
2017-07-07 18:12:44 -05:00
|
|
|
}));
|
|
|
|
assert!(res.is_err());
|
|
|
|
assert_eq!(A.load(Ordering::SeqCst), 1);
|
|
|
|
}
|