File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff 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) )
Original file line number Diff line number Diff 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) )
You can’t perform that action at this time.
0 commit comments