2012-12-10 17:32:48 -08:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-10-23 04:49:18 -04:00
|
|
|
#[feature(managed_boxes)];
|
2010-08-27 13:27:28 -07:00
|
|
|
|
2012-01-19 18:31:08 -08:00
|
|
|
enum t { make_t(@int), clam, }
|
2010-08-27 13:27:28 -07:00
|
|
|
|
2011-08-31 15:23:34 -07:00
|
|
|
fn foo(s: @int) {
|
2013-10-21 13:08:31 -07:00
|
|
|
info!("{:?}", ::std::managed::refcount(s));
|
2013-10-17 21:13:56 -07:00
|
|
|
let count = ::std::managed::refcount(s);
|
2011-07-27 14:19:39 +02:00
|
|
|
let x: t = make_t(s); // ref up
|
2013-10-17 21:13:56 -07:00
|
|
|
assert_eq!(::std::managed::refcount(s), count + 1u);
|
2013-10-21 13:08:31 -07:00
|
|
|
info!("{:?}", ::std::managed::refcount(s));
|
2010-08-27 13:27:28 -07:00
|
|
|
|
2012-08-06 12:34:08 -07:00
|
|
|
match x {
|
2012-08-03 19:59:04 -07:00
|
|
|
make_t(y) => {
|
2013-10-21 13:08:31 -07:00
|
|
|
info!("{:?}", y); // ref up then down
|
2010-08-27 13:27:28 -07:00
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
}
|
2013-10-21 13:08:31 -07:00
|
|
|
_ => { info!("?"); fail!(); }
|
2011-06-15 11:19:50 -07:00
|
|
|
}
|
2013-10-21 13:08:31 -07:00
|
|
|
info!("{:?}", ::std::managed::refcount(s));
|
2013-10-17 21:13:56 -07:00
|
|
|
assert_eq!(::std::managed::refcount(s), count + 1u);
|
|
|
|
let _ = ::std::managed::refcount(s); // don't get bitten by last-use.
|
2010-08-27 13:48:45 -07:00
|
|
|
}
|
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2011-08-31 15:23:34 -07:00
|
|
|
let s: @int = @0; // ref up
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2013-10-17 21:13:56 -07:00
|
|
|
let count = ::std::managed::refcount(s);
|
2012-06-04 10:44:19 -07:00
|
|
|
|
2011-06-15 11:19:50 -07:00
|
|
|
foo(s); // ref up then down
|
|
|
|
|
2013-10-21 13:08:31 -07:00
|
|
|
info!("{}", ::std::managed::refcount(s));
|
2013-10-17 21:13:56 -07:00
|
|
|
let count2 = ::std::managed::refcount(s);
|
2013-04-26 14:04:39 -07:00
|
|
|
assert_eq!(count, count2);
|
2011-08-19 15:16:48 -07:00
|
|
|
}
|