Add internal safety docs to (A)Rc::into_raw

This commit is contained in:
CAD97
2019-12-17 15:52:13 -05:00
parent c842f02dee
commit eb77f7ec6e
2 changed files with 10 additions and 0 deletions
+5
View File
@@ -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))
+5
View File
@@ -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))