diff options
| author | zhiqiangxu <652732310@qq.com> | 2023-12-06 09:02:19 +0800 |
|---|---|---|
| committer | zhiqiangxu <652732310@qq.com> | 2023-12-06 09:02:19 +0800 |
| commit | 75d76c8ffedf0c0bc72f6d6569c6b2521d834457 (patch) | |
| tree | 14c84f88d4ca3b1b670a07c683a3e587dcf2d173 | |
| parent | 9144d511758fdd85db4daeeea1020f62c61bdd04 (diff) | |
| download | rust-75d76c8ffedf0c0bc72f6d6569c6b2521d834457.tar.gz rust-75d76c8ffedf0c0bc72f6d6569c6b2521d834457.zip | |
Don't repeat yourself
| -rw-r--r-- | library/alloc/src/sync.rs | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 351e6c1a4b3..e2f0ccd9aa2 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 } }) } } |
