From dcde4fe920998a60c928e81f9648623a4d139990 Mon Sep 17 00:00:00 2001 From: edef Date: Sun, 5 Mar 2017 20:34:04 +0100 Subject: [PATCH] Don't use unsafe for the forget_yielded test Now that the Send bound is gone, we can simply use a Cell instead of a raw pointer. --- tests/generator.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/generator.rs b/tests/generator.rs index fda5489..603ecc8 100644 --- a/tests/generator.rs +++ b/tests/generator.rs @@ -85,23 +85,22 @@ fn with_owned_stack() { #[test] fn forget_yielded() { - struct Dropper(*mut bool); + use std::cell::Cell; + struct Dropper<'a>(&'a Cell); - impl Drop for Dropper { + impl<'a> Drop for Dropper<'a> { fn drop(&mut self) { - unsafe { - if *self.0 { - panic!("double drop!") - } - *self.0 = true; + if self.0.get() { + panic!("double drop!") } + self.0.set(true); } } let stack = fringe::OsStack::new(1<<16).unwrap(); + let flag = Cell::new(false); let mut generator = Generator::new(stack, |yielder, ()| { - let mut flag = false; - yielder.suspend(Dropper(&mut flag as *mut bool)); + yielder.suspend(Dropper(&flag)); }); generator.resume(()); generator.resume(());