1 //! Tests that panics inside a generator will correctly drop the initial resume argument.
4 // ignore-wasm no unwind support
5 // ignore-emscripten no unwind support
7 #![feature(generators, generator_trait)]
9 use std::ops::Generator;
10 use std::panic::{catch_unwind, AssertUnwindSafe};
12 use std::sync::atomic::{AtomicUsize, Ordering};
14 static DROP: AtomicUsize = AtomicUsize::new(0);
18 impl Drop for Dropper {
20 DROP.fetch_add(1, Ordering::SeqCst);
25 let mut gen = |_arg| {
31 let mut gen = Pin::new(&mut gen);
33 assert_eq!(DROP.load(Ordering::Acquire), 0);
34 let res = catch_unwind(AssertUnwindSafe(|| gen.as_mut().resume(Dropper {})));
35 assert!(res.is_err());
36 assert_eq!(DROP.load(Ordering::Acquire), 1);