diff options
| author | bors <bors@rust-lang.org> | 2023-12-30 11:40:42 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-12-30 11:40:42 +0000 |
| commit | d59f06fc64844ec2073e5e888f7470989ef25ff9 (patch) | |
| tree | 8e7a3d6f6f3ee36a2370ec584af9c8c4431220bc /library/alloc/src | |
| parent | c2354aabeaac01f1530b4439eb2339b1c15aceb4 (diff) | |
| parent | e930ea274e1b0cdc9f69b0e57f71c3893204aca6 (diff) | |
| download | rust-d59f06fc64844ec2073e5e888f7470989ef25ff9.tar.gz rust-d59f06fc64844ec2073e5e888f7470989ef25ff9.zip | |
Auto merge of #119437 - matthiaskrgr:rollup-esf96p6, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #119158 (Clean up alloc::sync::Weak Clone implementation) - #119386 (fix typo in `IpAddr::to_canonical`) - #119413 (solaris support on bootstrap lock) - #119424 (Primitive docs: fix confusing `Send` in `&T`'s list) - #119425 (Fix invalid check-cfg Cargo feature diagnostic help) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/sync.rs | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 85df491636a..1fc6fe631ab 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -2917,20 +2917,17 @@ impl<T: ?Sized, A: Allocator + Clone> Clone for Weak<T, A> { /// ``` #[inline] fn clone(&self) -> Weak<T, A> { - let inner = if let Some(inner) = self.inner() { - inner - } else { - return Weak { ptr: self.ptr, alloc: self.alloc.clone() }; - }; - // See comments in Arc::clone() for why this is relaxed. This can use a - // fetch_add (ignoring the lock) because the weak count is only locked - // where are *no other* weak pointers in existence. (So we can't be - // running this code in that case). - let old_size = inner.weak.fetch_add(1, Relaxed); - - // See comments in Arc::clone() for why we do this (for mem::forget). - if old_size > MAX_REFCOUNT { - abort(); + if let Some(inner) = self.inner() { + // See comments in Arc::clone() for why this is relaxed. This can use a + // fetch_add (ignoring the lock) because the weak count is only locked + // where are *no other* weak pointers in existence. (So we can't be + // running this code in that case). + let old_size = inner.weak.fetch_add(1, Relaxed); + + // See comments in Arc::clone() for why we do this (for mem::forget). + if old_size > MAX_REFCOUNT { + abort(); + } } Weak { ptr: self.ptr, alloc: self.alloc.clone() } |
