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

33 lines
479 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;
2012-08-15 20:46:55 -05:00
struct close_res {
2012-09-06 21:40:15 -05:00
i: closable,
}
impl close_res : Drop {
fn finalize(&self) {
*(self.i) = false;
}
}
2012-09-05 17:58:43 -05:00
fn close_res(i: closable) -> close_res {
close_res {
i: i
}
}
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);
}