Skip to content

Commit a1b25f2

Browse files
committed
auto merge of #9930 : alexcrichton/rust/refcount-tests, r=thestinger
This fixes a bug I accidentally introduced in #9922
2 parents d052912 + 6a11e17 commit a1b25f2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/libstd/managed.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub static RC_IMMORTAL : uint = 0x77777777;
2121
#[inline]
2222
pub fn refcount<T>(t: @T) -> uint {
2323
use unstable::raw::Repr;
24-
unsafe { (*t.repr()).ref_count }
24+
unsafe { (*t.repr()).ref_count - 1 }
2525
}
2626

2727
/// Determine if two shared boxes point to the same object
@@ -110,3 +110,14 @@ fn test() {
110110
assert!((!ptr_eq::<int>(x, y)));
111111
assert!((!ptr_eq::<int>(y, x)));
112112
}
113+
114+
#[test]
115+
fn refcount_test() {
116+
use clone::Clone;
117+
118+
let x = @3;
119+
assert_eq!(refcount(x), 1);
120+
let y = x.clone();
121+
assert_eq!(refcount(x), 2);
122+
assert_eq!(refcount(y), 2);
123+
}

0 commit comments

Comments
 (0)