mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-17 05:25:37 +03:00
Add internal safety docs to (A)Rc::into_raw
This commit is contained in:
@@ -575,6 +575,11 @@ pub fn into_raw(this: Self) -> *const T {
|
||||
let fake_ptr = ptr as *mut T;
|
||||
mem::forget(this);
|
||||
|
||||
// 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`.
|
||||
unsafe {
|
||||
let offset = data_offset(&(*ptr).value);
|
||||
set_data_ptr(fake_ptr, (ptr as *mut u8).offset(offset))
|
||||
|
||||
@@ -555,6 +555,11 @@ pub fn into_raw(this: Self) -> *const T {
|
||||
let fake_ptr = ptr as *mut T;
|
||||
mem::forget(this);
|
||||
|
||||
// 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`.
|
||||
unsafe {
|
||||
let offset = data_offset(&(*ptr).data);
|
||||
set_data_ptr(fake_ptr, (ptr as *mut u8).offset(offset))
|
||||
|
||||
Reference in New Issue
Block a user