Add internal safety docs to (A)Rc::into_raw
This commit is contained in:
parent
c842f02dee
commit
eb77f7ec6e
2 changed files with 10 additions and 0 deletions
|
@ -575,6 +575,11 @@ impl<T: ?Sized> Rc<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 @@ impl<T: ?Sized> Arc<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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue