2012-12-10 19:32:48 -06: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.
|
|
|
|
|
2010-08-27 15:27:28 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
|
|
|
|
// -*- rust -*-
|
2012-01-19 20:31:08 -06:00
|
|
|
enum t { make_t(@int), clam, }
|
2010-08-27 15:27:28 -05:00
|
|
|
|
2011-08-31 17:23:34 -05:00
|
|
|
fn foo(s: @int) {
|
2013-01-07 20:54:28 -06:00
|
|
|
let count = ::core::sys::refcount(s);
|
2011-07-27 07:19:39 -05:00
|
|
|
let x: t = make_t(s); // ref up
|
2010-08-27 15:27:28 -05:00
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match x {
|
2012-08-03 21:59:04 -05:00
|
|
|
make_t(y) => {
|
2011-12-22 19:53:53 -06:00
|
|
|
log(debug, y); // ref up then down
|
2010-08-27 15:27:28 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2013-02-11 21:26:38 -06:00
|
|
|
_ => { debug!("?"); fail!(); }
|
2011-06-15 13:19:50 -05:00
|
|
|
}
|
2013-01-07 20:54:28 -06:00
|
|
|
log(debug, ::core::sys::refcount(s));
|
|
|
|
assert (::core::sys::refcount(s) == count + 1u);
|
|
|
|
let _ = ::core::sys::refcount(s); // don't get bitten by last-use.
|
2010-08-27 15:48:45 -05:00
|
|
|
}
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2011-08-31 17:23:34 -05:00
|
|
|
let s: @int = @0; // ref up
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2013-01-07 20:54:28 -06:00
|
|
|
let count = ::core::sys::refcount(s);
|
2012-06-04 12:44:19 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
foo(s); // ref up then down
|
|
|
|
|
2013-01-07 20:54:28 -06:00
|
|
|
log(debug, ::core::sys::refcount(s));
|
|
|
|
let count2 = ::core::sys::refcount(s);
|
|
|
|
let _ = ::core::sys::refcount(s); // don't get bitten by last-use.
|
2012-06-28 14:59:43 -05:00
|
|
|
assert count == count2;
|
2011-08-19 17:16:48 -05:00
|
|
|
}
|