1 //! Tests that panics inside a generator will correctly drop the initial resume argument.
5 // ignore-wasm no unwind support
6 // ignore-emscripten no unwind support
8 #![feature(generators, generator_trait)]
10 use std::ops::Generator;
11 use std::panic::{catch_unwind, AssertUnwindSafe};
13 use std::sync::atomic::{AtomicUsize, Ordering};
15 static DROP: AtomicUsize = AtomicUsize::new(0);
19 impl Drop for Dropper {
21 DROP.fetch_add(1, Ordering::SeqCst);
26 let mut gen = |_arg| {
32 let mut gen = Pin::new(&mut gen);
34 assert_eq!(DROP.load(Ordering::Acquire), 0);
35 let res = catch_unwind(AssertUnwindSafe(|| gen.as_mut().resume(Dropper {})));
36 assert!(res.is_err());
37 assert_eq!(DROP.load(Ordering::Acquire), 1);