about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-10-18 11:31:31 -0700
committerbors <bors@rust-lang.org>2013-10-18 11:31:31 -0700
commita1b25f2f09485ccb3d5ca07e2886a9a6dc9bc16b (patch)
tree0320dae4d675462159053734783928de49756149 /src/libstd
parentd0529122975919ca4d85c14116617f75cb7a6e6f (diff)
parent6a11e17b6bf64f1676a69d45edd336c8697a931b (diff)
downloadrust-a1b25f2f09485ccb3d5ca07e2886a9a6dc9bc16b.tar.gz
rust-a1b25f2f09485ccb3d5ca07e2886a9a6dc9bc16b.zip
auto merge of #9930 : alexcrichton/rust/refcount-tests, r=thestinger
This fixes a bug I accidentally introduced in #9922
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/managed.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/libstd/managed.rs b/src/libstd/managed.rs
index a27c8aa4a76..7322f0b0647 100644
--- a/src/libstd/managed.rs
+++ b/src/libstd/managed.rs
@@ -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);
+}