From 98789ac75a15c78462ada2438881c8a4e4fda94a Mon Sep 17 00:00:00 2001 From: CAD97 Date: Wed, 1 Jul 2020 15:03:12 -0400 Subject: [PATCH] Simplify Weak::as_ptr impl --- src/liballoc/rc.rs | 5 ++--- src/liballoc/sync.rs | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 29e0979b0eda..4d77779b2091 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1703,7 +1703,6 @@ impl Weak { #[stable(feature = "weak_into_raw", since = "1.45.0")] pub fn as_ptr(&self) -> *const T { let ptr: *mut RcBox = NonNull::as_ptr(self.ptr); - let fake_ptr = ptr as *mut T; // SAFETY: we must offset the pointer manually, and said pointer may be // a dangling weak (usize::MAX). data_offset is safe to call, because we @@ -1712,8 +1711,8 @@ impl Weak { // is used so that we can use the same code path for the non-dangling // unsized case and the potentially dangling sized case. unsafe { - let offset = data_offset(fake_ptr); - set_data_ptr(fake_ptr, (ptr as *mut u8).wrapping_offset(offset)) + let offset = data_offset(ptr as *mut T); + set_data_ptr(ptr as *mut T, (ptr as *mut u8).wrapping_offset(offset)) } } diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 005821980fe2..160abe7210c7 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -1471,7 +1471,6 @@ impl Weak { #[stable(feature = "weak_into_raw", since = "1.45.0")] pub fn as_ptr(&self) -> *const T { let ptr: *mut ArcInner = NonNull::as_ptr(self.ptr); - let fake_ptr = ptr as *mut T; // SAFETY: we must offset the pointer manually, and said pointer may be // a dangling weak (usize::MAX). data_offset is safe to call, because we @@ -1480,8 +1479,8 @@ impl Weak { // is used so that we can use the same code path for the non-dangling // unsized case and the potentially dangling sized case. unsafe { - let offset = data_offset(fake_ptr); - set_data_ptr(fake_ptr, (ptr as *mut u8).wrapping_offset(offset)) + let offset = data_offset(ptr as *mut T); + set_data_ptr(ptr as *mut T, (ptr as *mut u8).wrapping_offset(offset)) } }