File tree 2 files changed +10
-0
lines changed
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> {
575
575
let fake_ptr = ptr as * mut T ;
576
576
mem:: forget ( this) ;
577
577
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`.
578
583
unsafe {
579
584
let offset = data_offset ( & ( * ptr) . value ) ;
580
585
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> {
555
555
let fake_ptr = ptr as * mut T ;
556
556
mem:: forget ( this) ;
557
557
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`.
558
563
unsafe {
559
564
let offset = data_offset ( & ( * ptr) . data ) ;
560
565
set_data_ptr ( fake_ptr, ( ptr as * mut u8 ) . offset ( offset) )
You can’t perform that action at this time.
0 commit comments