Skip to content

Commit db539c6

Browse files
committed
Use raw_ref_op in A|Rc::as_ptr
1 parent 25687ca commit db539c6

File tree

3 files changed

+3
-10
lines changed

3 files changed

+3
-10
lines changed

src/liballoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
#![feature(pattern)]
110110
#![feature(ptr_internals)]
111111
#![feature(ptr_offset_from)]
112+
#![feature(raw_ref_op)]
112113
#![feature(rustc_attrs)]
113114
#![feature(receiver_trait)]
114115
#![feature(min_specialization)]

src/liballoc/rc.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -591,17 +591,13 @@ impl<T: ?Sized> Rc<T> {
591591
#[stable(feature = "weak_into_raw", since = "1.45.0")]
592592
pub fn as_ptr(this: &Self) -> *const T {
593593
let ptr: *mut RcBox<T> = NonNull::as_ptr(this.ptr);
594-
let fake_ptr = ptr as *mut T;
595594

596595
// SAFETY: This cannot go through Deref::deref.
597596
// Instead, we manually offset the pointer rather than manifesting a reference.
598597
// This is so that the returned pointer retains the same provenance as our pointer.
599598
// This is required so that e.g. `get_mut` can write through the pointer
600599
// after the Rc is recovered through `from_raw`.
601-
unsafe {
602-
let offset = data_offset(&(*ptr).value);
603-
set_data_ptr(fake_ptr, (ptr as *mut u8).offset(offset))
604-
}
600+
unsafe { &raw const (*ptr).value }
605601
}
606602

607603
/// Constructs an `Rc<T>` from a raw pointer.

src/liballoc/sync.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -590,17 +590,13 @@ impl<T: ?Sized> Arc<T> {
590590
#[stable(feature = "weak_into_raw", since = "1.45.0")]
591591
pub fn as_ptr(this: &Self) -> *const T {
592592
let ptr: *mut ArcInner<T> = NonNull::as_ptr(this.ptr);
593-
let fake_ptr = ptr as *mut T;
594593

595594
// SAFETY: This cannot go through Deref::deref.
596595
// Instead, we manually offset the pointer rather than manifesting a reference.
597596
// This is so that the returned pointer retains the same provenance as our pointer.
598597
// This is required so that e.g. `get_mut` can write through the pointer
599598
// after the Arc is recovered through `from_raw`.
600-
unsafe {
601-
let offset = data_offset(&(*ptr).data);
602-
set_data_ptr(fake_ptr, (ptr as *mut u8).offset(offset))
603-
}
599+
unsafe { &raw const (*ptr).data }
604600
}
605601

606602
/// Constructs an `Arc<T>` from a raw pointer.

0 commit comments

Comments
 (0)