rust/src/test/run-pass/resource-in-struct.rs

23 lines
384 B
Rust
Raw Normal View History

// Ensures that class dtors run if the object is inside an enum
// variant
2012-03-26 20:35:18 -05:00
type closable = @mut bool;
class close_res {
let i: closable;
new(i: closable) { self.i = i; }
drop { *(self.i) = false; }
}
enum option<T> { none, some(T), }
fn sink(res: option<close_res>) { }
fn main() {
2012-03-26 20:35:18 -05:00
let c = @mut true;
sink(none);
sink(some(close_res(c)));
assert (!*c);
}