// option. This file may not be copied, modified, or distributed
// except according to those terms.
+
+#![feature(unsafe_destructor)]
+
// Ensures that class dtors run if the object is inside an enum
// variant
-type closable = @mut bool;
+use std::cell::Cell;
+
+type closable<'a> = &'a Cell<bool>;
-struct close_res {
- i: closable,
+struct close_res<'a> {
+ i: closable<'a>,
}
#[unsafe_destructor]
-impl Drop for close_res {
- fn finalize(&self) {
- unsafe {
- *(self.i) = false;
- }
+impl<'a> Drop for close_res<'a> {
+ fn drop(&mut self) {
+ self.i.set(false);
}
}
enum option<T> { none, some(T), }
-fn sink(res: option<close_res>) { }
+fn sink(_res: option<close_res>) { }
pub fn main() {
- let c = @mut true;
- sink(none);
- sink(some(close_res(c)));
- assert!((!*c));
+ let c = &Cell::new(true);
+ sink(option::none);
+ sink(option::some(close_res(c)));
+ assert!(!c.get());
}