Skip to content

Commit

Permalink
Don't use unsafe for the forget_yielded test
Browse files Browse the repository at this point in the history
Now that the Send bound is gone, we can simply use a Cell instead of a
raw pointer.
  • Loading branch information
edef1c committed Mar 6, 2017
1 parent af17712 commit 2b64d96
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions tests/generator.rs
Expand Up @@ -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<bool>);

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(());
Expand Down

0 comments on commit 2b64d96

Please sign in to comment.