summaryrefslogtreecommitdiffstats
path: root/tests/ui/coroutine/panic-drops.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/coroutine/panic-drops.rs')
-rw-r--r--tests/ui/coroutine/panic-drops.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/ui/coroutine/panic-drops.rs b/tests/ui/coroutine/panic-drops.rs
new file mode 100644
index 000000000..7e37279b9
--- /dev/null
+++ b/tests/ui/coroutine/panic-drops.rs
@@ -0,0 +1,57 @@
+// run-pass
+// needs-unwind
+
+
+#![feature(coroutines, coroutine_trait)]
+
+use std::ops::Coroutine;
+use std::panic;
+use std::pin::Pin;
+use std::sync::atomic::{AtomicUsize, Ordering};
+
+static A: AtomicUsize = AtomicUsize::new(0);
+
+struct B;
+
+impl Drop for B {
+ fn drop(&mut self) {
+ A.fetch_add(1, Ordering::SeqCst);
+ }
+}
+
+fn bool_true() -> bool {
+ true
+}
+
+fn main() {
+ let b = B;
+ let mut foo = || {
+ if bool_true() {
+ panic!();
+ }
+ drop(b);
+ yield;
+ };
+
+ assert_eq!(A.load(Ordering::SeqCst), 0);
+ let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
+ Pin::new(&mut foo).resume(())
+ }));
+ assert!(res.is_err());
+ assert_eq!(A.load(Ordering::SeqCst), 1);
+
+ let mut foo = || {
+ if bool_true() {
+ panic!();
+ }
+ drop(B);
+ yield;
+ };
+
+ assert_eq!(A.load(Ordering::SeqCst), 1);
+ let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
+ Pin::new(&mut foo).resume(())
+ }));
+ assert!(res.is_err());
+ assert_eq!(A.load(Ordering::SeqCst), 1);
+}