diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-10-18 09:22:03 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-10-18 09:33:18 -0700 |
| commit | 6a11e17b6bf64f1676a69d45edd336c8697a931b (patch) | |
| tree | c898ff02d6cfb8076859ab8182d03a0e31473f5f | |
| parent | a1848bc755411285afb15f2453df7567e10ebc04 (diff) | |
| download | rust-6a11e17b6bf64f1676a69d45edd336c8697a931b.tar.gz rust-6a11e17b6bf64f1676a69d45edd336c8697a931b.zip | |
Fix an off-by-one in managed::refcount
This fixes a bug I accidentally introduced in #9922
| -rw-r--r-- | src/libstd/managed.rs | 13 |
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); +} |
