2010-08-27 15:27:28 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
|
|
|
|
// -*- rust -*-
|
2010-08-27 15:27:28 -05:00
|
|
|
use std;
|
2011-05-17 13:41:41 -05:00
|
|
|
import std::str;
|
2010-08-27 15:27:28 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
// FIXME: import std::dbg.const_refcount. Currently
|
2010-11-09 16:15:07 -06:00
|
|
|
// cross-crate const references don't work.
|
|
|
|
const uint const_refcount = 0x7bad_face_u;
|
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
tag t { make_t(str); clam; }
|
2010-08-27 15:27:28 -05:00
|
|
|
|
2010-08-27 15:48:45 -05:00
|
|
|
fn foo(str s) {
|
2011-06-15 13:19:50 -05:00
|
|
|
let t x = make_t(s); // ref up
|
2010-08-27 15:27:28 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
alt (x) {
|
|
|
|
case (make_t(?y)) {
|
|
|
|
log y; // ref up then down
|
2010-08-27 15:27:28 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
}
|
|
|
|
case (_) { log "?"; fail; }
|
|
|
|
}
|
|
|
|
log str::refcount(s);
|
|
|
|
assert (str::refcount(s) == const_refcount);
|
2010-08-27 15:48:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2011-06-15 13:19:50 -05:00
|
|
|
let str s = "hi"; // ref up
|
|
|
|
|
|
|
|
foo(s); // ref up then down
|
|
|
|
|
|
|
|
log str::refcount(s);
|
|
|
|
assert (str::refcount(s) == const_refcount);
|
|
|
|
}
|