about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-12-07 02:27:41 +0000
committerbors <bors@rust-lang.org>2023-12-07 02:27:41 +0000
commitc9d85d67c48a4d9b8b78ed9d7273b4608f0fef02 (patch)
treeb1c2bfef3dfc9e0fb6f038a51b9b0ba859e2b72f
parent670188cec980446b4a6e0da9e68d8a5c9571643d (diff)
parent75d76c8ffedf0c0bc72f6d6569c6b2521d834457 (diff)
downloadrust-c9d85d67c48a4d9b8b78ed9d7273b4608f0fef02.tar.gz
rust-c9d85d67c48a4d9b8b78ed9d7273b4608f0fef02.zip
Auto merge of #117960 - zhiqiangxu:dry, r=workingjubilee
chore: avoid duplicate code in `Weak::inner`
-rw-r--r--library/alloc/src/sync.rs8
1 files changed, 3 insertions, 5 deletions
diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs
index da0abdc9746..5a4a94d79d8 100644
--- a/library/alloc/src/sync.rs
+++ b/library/alloc/src/sync.rs
@@ -2843,16 +2843,14 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
     /// (i.e., when this `Weak` was created by `Weak::new`).
     #[inline]
     fn inner(&self) -> Option<WeakInner<'_>> {
-        if is_dangling(self.ptr.as_ptr()) {
+        let ptr = self.ptr.as_ptr();
+        if is_dangling(ptr) {
             None
         } else {
             // We are careful to *not* create a reference covering the "data" field, as
             // the field may be mutated concurrently (for example, if the last `Arc`
             // is dropped, the data field will be dropped in-place).
-            Some(unsafe {
-                let ptr = self.ptr.as_ptr();
-                WeakInner { strong: &(*ptr).strong, weak: &(*ptr).weak }
-            })
+            Some(unsafe { WeakInner { strong: &(*ptr).strong, weak: &(*ptr).weak } })
         }
     }