mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-17 05:25:37 +03:00
Clarify safety comment for A|Rc::as_ptr
This commit is contained in:
+3
-5
@@ -592,11 +592,9 @@ pub fn into_raw(this: Self) -> *const T {
|
||||
pub fn as_ptr(this: &Self) -> *const T {
|
||||
let ptr: *mut RcBox<T> = NonNull::as_ptr(this.ptr);
|
||||
|
||||
// SAFETY: This cannot go through Deref::deref.
|
||||
// Instead, we manually offset the pointer rather than manifesting a reference.
|
||||
// This is so that the returned pointer retains the same provenance as our pointer.
|
||||
// This is required so that e.g. `get_mut` can write through the pointer
|
||||
// after the Rc is recovered through `from_raw`.
|
||||
// SAFETY: This cannot go through Deref::deref or Rc::inner.
|
||||
// This is required to retain raw/mut provenance such that e.g. `get_mut` can
|
||||
// write through the pointer after the Rc is recovered through `from_raw`.
|
||||
unsafe { &raw const (*ptr).value }
|
||||
}
|
||||
|
||||
|
||||
@@ -591,11 +591,9 @@ pub fn into_raw(this: Self) -> *const T {
|
||||
pub fn as_ptr(this: &Self) -> *const T {
|
||||
let ptr: *mut ArcInner<T> = NonNull::as_ptr(this.ptr);
|
||||
|
||||
// SAFETY: This cannot go through Deref::deref.
|
||||
// Instead, we manually offset the pointer rather than manifesting a reference.
|
||||
// This is so that the returned pointer retains the same provenance as our pointer.
|
||||
// This is required so that e.g. `get_mut` can write through the pointer
|
||||
// after the Arc is recovered through `from_raw`.
|
||||
// SAFETY: This cannot go through Deref::deref or RcBoxPtr::inner.
|
||||
// This is required to retain raw/mut provenance such that e.g. `get_mut` can
|
||||
// write through the pointer after the Rc is recovered through `from_raw`.
|
||||
unsafe { &raw const (*ptr).data }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user