auto merge of #9930 : alexcrichton/rust/refcount-tests, r=thestinger

This fixes a bug I accidentally introduced in #9922
This commit is contained in:
bors 2013-10-18 11:31:31 -07:00
commit a1b25f2f09

View File

@ -21,7 +21,7 @@ pub static RC_IMMORTAL : uint = 0x77777777;
#[inline]
pub fn refcount<T>(t: @T) -> uint {
use unstable::raw::Repr;
unsafe { (*t.repr()).ref_count }
unsafe { (*t.repr()).ref_count - 1 }
}
/// Determine if two shared boxes point to the same object
@ -110,3 +110,14 @@ fn test() {
assert!((!ptr_eq::<int>(x, y)));
assert!((!ptr_eq::<int>(y, x)));
}
#[test]
fn refcount_test() {
use clone::Clone;
let x = @3;
assert_eq!(refcount(x), 1);
let y = x.clone();
assert_eq!(refcount(x), 2);
assert_eq!(refcount(y), 2);
}