Skip to content

Commit eb77f7e

Browse files
committed
Add internal safety docs to (A)Rc::into_raw
1 parent c842f02 commit eb77f7e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/liballoc/rc.rs

+5
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,11 @@ impl<T: ?Sized> Rc<T> {
575575
let fake_ptr = ptr as *mut T;
576576
mem::forget(this);
577577

578+
// SAFETY: This cannot go through Deref::deref.
579+
// Instead, we manually offset the pointer rather than manifesting a reference.
580+
// This is so that the returned pointer retains the same provenance as our pointer.
581+
// This is required so that e.g. `get_mut` can write through the pointer
582+
// after the Rc is recovered through `from_raw`.
578583
unsafe {
579584
let offset = data_offset(&(*ptr).value);
580585
set_data_ptr(fake_ptr, (ptr as *mut u8).offset(offset))

src/liballoc/sync.rs

+5
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,11 @@ impl<T: ?Sized> Arc<T> {
555555
let fake_ptr = ptr as *mut T;
556556
mem::forget(this);
557557

558+
// SAFETY: This cannot go through Deref::deref.
559+
// Instead, we manually offset the pointer rather than manifesting a reference.
560+
// This is so that the returned pointer retains the same provenance as our pointer.
561+
// This is required so that e.g. `get_mut` can write through the pointer
562+
// after the Arc is recovered through `from_raw`.
558563
unsafe {
559564
let offset = data_offset(&(*ptr).data);
560565
set_data_ptr(fake_ptr, (ptr as *mut u8).offset(offset))

0 commit comments

Comments
 (0)