Skip to content

Commit

Permalink
auto merge of #9930 : alexcrichton/rust/refcount-tests, r=thestinger
Browse files Browse the repository at this point in the history
This fixes a bug I accidentally introduced in #9922
  • Loading branch information
bors committed Oct 18, 2013
2 parents d052912 + 6a11e17 commit a1b25f2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/libstd/managed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

0 comments on commit a1b25f2

Please sign in to comment.