Skip to content

Commit 98789ac

Browse files
committed
Simplify Weak::as_ptr impl
1 parent ac40d1e commit 98789ac

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/liballoc/rc.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,6 @@ impl<T> Weak<T> {
17031703
#[stable(feature = "weak_into_raw", since = "1.45.0")]
17041704
pub fn as_ptr(&self) -> *const T {
17051705
let ptr: *mut RcBox<T> = NonNull::as_ptr(self.ptr);
1706-
let fake_ptr = ptr as *mut T;
17071706

17081707
// SAFETY: we must offset the pointer manually, and said pointer may be
17091708
// a dangling weak (usize::MAX). data_offset is safe to call, because we
@@ -1712,8 +1711,8 @@ impl<T> Weak<T> {
17121711
// is used so that we can use the same code path for the non-dangling
17131712
// unsized case and the potentially dangling sized case.
17141713
unsafe {
1715-
let offset = data_offset(fake_ptr);
1716-
set_data_ptr(fake_ptr, (ptr as *mut u8).wrapping_offset(offset))
1714+
let offset = data_offset(ptr as *mut T);
1715+
set_data_ptr(ptr as *mut T, (ptr as *mut u8).wrapping_offset(offset))
17171716
}
17181717
}
17191718

src/liballoc/sync.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,6 @@ impl<T> Weak<T> {
14711471
#[stable(feature = "weak_into_raw", since = "1.45.0")]
14721472
pub fn as_ptr(&self) -> *const T {
14731473
let ptr: *mut ArcInner<T> = NonNull::as_ptr(self.ptr);
1474-
let fake_ptr = ptr as *mut T;
14751474

14761475
// SAFETY: we must offset the pointer manually, and said pointer may be
14771476
// a dangling weak (usize::MAX). data_offset is safe to call, because we
@@ -1480,8 +1479,8 @@ impl<T> Weak<T> {
14801479
// is used so that we can use the same code path for the non-dangling
14811480
// unsized case and the potentially dangling sized case.
14821481
unsafe {
1483-
let offset = data_offset(fake_ptr);
1484-
set_data_ptr(fake_ptr, (ptr as *mut u8).wrapping_offset(offset))
1482+
let offset = data_offset(ptr as *mut T);
1483+
set_data_ptr(ptr as *mut T, (ptr as *mut u8).wrapping_offset(offset))
14851484
}
14861485
}
14871486

0 commit comments

Comments
 (0)