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

45 lines
1.3 KiB
Rust
Raw Normal View History

// 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)];
enum t { make_t(@int), clam, }
2011-08-31 15:23:34 -07:00
fn foo(s: @int) {
info!("{:?}", ::std::managed::refcount(s));
let count = ::std::managed::refcount(s);
2011-07-27 14:19:39 +02:00
let x: t = make_t(s); // ref up
assert_eq!(::std::managed::refcount(s), count + 1u);
info!("{:?}", ::std::managed::refcount(s));
2012-08-06 12:34:08 -07:00
match x {
2012-08-03 19:59:04 -07:00
make_t(y) => {
info!("{:?}", y); // ref up then down
2011-07-27 14:19:39 +02:00
}
_ => { info!("?"); fail!(); }
}
info!("{:?}", ::std::managed::refcount(s));
assert_eq!(::std::managed::refcount(s), count + 1u);
let _ = ::std::managed::refcount(s); // don't get bitten by last-use.
}
pub fn main() {
2011-08-31 15:23:34 -07:00
let s: @int = @0; // ref up
let count = ::std::managed::refcount(s);
foo(s); // ref up then down
info!("{}", ::std::managed::refcount(s));
let count2 = ::std::managed::refcount(s);
2013-04-26 14:04:39 -07:00
assert_eq!(count, count2);
}