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

36 lines
612 B
Rust
Raw Normal View History

// -*- rust -*-
use std;
import std::str;
// FIXME: import std::dbg.const_refcount. Currently
// cross-crate const references don't work.
2011-07-27 07:19:39 -05:00
const const_refcount: uint = 0x7bad_face_u;
tag t { make_t(str); clam; }
2011-07-27 07:19:39 -05:00
fn foo(s: str) {
let x: t = make_t(s); // ref up
2011-07-27 07:19:39 -05:00
alt x {
make_t(y) {
log y; // ref up then down
2011-07-27 07:19:39 -05:00
}
_ { log "?"; fail; }
}
log str::refcount(s);
assert (str::refcount(s) == const_refcount);
}
fn main() {
2011-07-27 07:19:39 -05:00
let s: str = "hi"; // ref up
foo(s); // ref up then down
log str::refcount(s);
assert (str::refcount(s) == const_refcount);
}