diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-16 05:23:26 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-16 05:23:26 +0100 |
| commit | c34ea91a9dbea9b23653dc39cb09e5d412353359 (patch) | |
| tree | 9c0a6a2c865a4204d1dde9d4d6885903f33fda55 /src/liballoc/sync | |
| parent | a605441e049f0b6d5f7715b94b8ac4662fd7fcf6 (diff) | |
| parent | 9778e03665edbed80eb684ba893abd4e18a0a583 (diff) | |
| download | rust-c34ea91a9dbea9b23653dc39cb09e5d412353359.tar.gz rust-c34ea91a9dbea9b23653dc39cb09e5d412353359.zip | |
Rollup merge of #65778 - bdonlan:stable_weak_count, r=dtolnay
Stabilize `std::{rc,sync}::Weak::{weak_count, strong_count}`
* Original PR: #56696
* Tracking issue: #57977
Closes: #57977
Supporting comments:
> Although these were added for testing, it is occasionally useful to have a way to probe optimistically for whether a weak pointer has become dangling, without actually taking the overhead of manipulating atomics. Are there any plans to stabilize this?
_Originally posted by @bdonlan in https://github.com/rust-lang/rust/issues/57977#issuecomment-516970921_
> Having this stabilized would help. Currently, the only way to check if a weak pointer has become dangling is to call `upgrade`, which is by far expensive.
_Originally posted by @glebpom in https://github.com/rust-lang/rust/issues/57977#issuecomment-526934709_
Not sure if stabilizing these warrants a full RFC, so throwing this out here as a start for now.
Note: per CONTRIBUTING.md, I ran the tidy checks, but they seem to be failing on unchanged files (primarily in `src/stdsimd`).
Diffstat (limited to 'src/liballoc/sync')
| -rw-r--r-- | src/liballoc/sync/tests.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/liballoc/sync/tests.rs b/src/liballoc/sync/tests.rs index 9ddba495b7e..8f516129cd0 100644 --- a/src/liballoc/sync/tests.rs +++ b/src/liballoc/sync/tests.rs @@ -62,28 +62,28 @@ fn test_arc_get_mut() { #[test] fn weak_counts() { - assert_eq!(Weak::weak_count(&Weak::<u64>::new()), None); + assert_eq!(Weak::weak_count(&Weak::<u64>::new()), 0); assert_eq!(Weak::strong_count(&Weak::<u64>::new()), 0); let a = Arc::new(0); let w = Arc::downgrade(&a); assert_eq!(Weak::strong_count(&w), 1); - assert_eq!(Weak::weak_count(&w), Some(1)); + assert_eq!(Weak::weak_count(&w), 1); let w2 = w.clone(); assert_eq!(Weak::strong_count(&w), 1); - assert_eq!(Weak::weak_count(&w), Some(2)); + assert_eq!(Weak::weak_count(&w), 2); assert_eq!(Weak::strong_count(&w2), 1); - assert_eq!(Weak::weak_count(&w2), Some(2)); + assert_eq!(Weak::weak_count(&w2), 2); drop(w); assert_eq!(Weak::strong_count(&w2), 1); - assert_eq!(Weak::weak_count(&w2), Some(1)); + assert_eq!(Weak::weak_count(&w2), 1); let a2 = a.clone(); assert_eq!(Weak::strong_count(&w2), 2); - assert_eq!(Weak::weak_count(&w2), Some(1)); + assert_eq!(Weak::weak_count(&w2), 1); drop(a2); drop(a); assert_eq!(Weak::strong_count(&w2), 0); - assert_eq!(Weak::weak_count(&w2), Some(1)); + assert_eq!(Weak::weak_count(&w2), 0); drop(w2); } |
