rust/src/test/run-pass/alt-pattern-drop.rs

33 lines
519 B
Rust
Raw Normal View History

// -*- rust -*-
use std;
2011-08-31 17:23:34 -05:00
import std::dbg;
enum t { make_t(@int), clam, }
2011-08-31 17:23:34 -05:00
fn foo(s: @int) {
let count = dbg::refcount(s);
2011-07-27 07:19:39 -05:00
let x: t = make_t(s); // ref up
2011-07-27 07:19:39 -05:00
alt x {
make_t(y) {
log(debug, y); // ref up then down
2011-07-27 07:19:39 -05:00
}
_ { #debug("?"); fail; }
}
log(debug, dbg::refcount(s));
2011-08-31 17:23:34 -05:00
assert (dbg::refcount(s) == count + 1u);
}
fn main() {
2011-08-31 17:23:34 -05:00
let s: @int = @0; // ref up
foo(s); // ref up then down
log(debug, dbg::refcount(s));
2011-08-31 17:23:34 -05:00
assert (dbg::refcount(s) == 1u);
}