1
0
Fork 0

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.
This commit is contained in:
edef 2017-03-05 20:34:04 +01:00
parent 661872f725
commit dcde4fe920
1 changed files with 8 additions and 9 deletions

View File

@ -85,23 +85,22 @@ fn with_owned_stack() {
#[test] #[test]
fn forget_yielded() { fn forget_yielded() {
struct Dropper(*mut bool); use std::cell::Cell;
struct Dropper<'a>(&'a Cell<bool>);
impl Drop for Dropper { impl<'a> Drop for Dropper<'a> {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { if self.0.get() {
if *self.0 { panic!("double drop!")
panic!("double drop!")
}
*self.0 = true;
} }
self.0.set(true);
} }
} }
let stack = fringe::OsStack::new(1<<16).unwrap(); let stack = fringe::OsStack::new(1<<16).unwrap();
let flag = Cell::new(false);
let mut generator = Generator::new(stack, |yielder, ()| { let mut generator = Generator::new(stack, |yielder, ()| {
let mut flag = false; yielder.suspend(Dropper(&flag));
yielder.suspend(Dropper(&mut flag as *mut bool));
}); });
generator.resume(()); generator.resume(());
generator.resume(()); generator.resume(());