rust/src/test/run-pass/while-prelude-drop.rs
2012-09-10 12:48:42 -07:00

40 lines
758 B
Rust

enum t { a, b(~str), }
impl t : cmp::Eq {
pure fn eq(&&other: t) -> bool {
match self {
a => {
match other {
a => true,
b(_) => false
}
}
b(s0) => {
match other {
a => false,
b(s1) => s0 == s1
}
}
}
}
pure fn ne(&&other: t) -> bool { !self.eq(other) }
}
fn make(i: int) -> t {
if i > 10 { return a; }
let mut s = ~"hello";
// Ensure s is non-const.
s += ~"there";
return b(s);
}
fn main() {
let mut i = 0;
// The auto slot for the result of make(i) should not leak.
while make(i) != a { i += 1; }
}