File tree 2 files changed +14
-4
lines changed
2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -571,9 +571,14 @@ impl<T: ?Sized> Rc<T> {
571
571
/// ```
572
572
#[ stable( feature = "rc_raw" , since = "1.17.0" ) ]
573
573
pub fn into_raw ( this : Self ) -> * const T {
574
- let ptr: * const T = & * this;
574
+ let ptr: * mut RcBox < T > = NonNull :: as_ptr ( this. ptr ) ;
575
+ let fake_ptr = ptr as * mut T ;
575
576
mem:: forget ( this) ;
576
- ptr
577
+
578
+ unsafe {
579
+ let offset = data_offset ( & ( * ptr) . value ) ;
580
+ set_data_ptr ( fake_ptr, ( ptr as * mut u8 ) . offset ( offset) )
581
+ }
577
582
}
578
583
579
584
/// Constructs an `Rc` from a raw pointer.
Original file line number Diff line number Diff line change @@ -551,9 +551,14 @@ impl<T: ?Sized> Arc<T> {
551
551
/// ```
552
552
#[ stable( feature = "rc_raw" , since = "1.17.0" ) ]
553
553
pub fn into_raw ( this : Self ) -> * const T {
554
- let ptr: * const T = & * this;
554
+ let ptr: * mut ArcInner < T > = NonNull :: as_ptr ( this. ptr ) ;
555
+ let fake_ptr = ptr as * mut T ;
555
556
mem:: forget ( this) ;
556
- ptr
557
+
558
+ unsafe {
559
+ let offset = data_offset ( & ( * ptr) . data ) ;
560
+ set_data_ptr ( fake_ptr, ( ptr as * mut u8 ) . offset ( offset) )
561
+ }
557
562
}
558
563
559
564
/// Constructs an `Arc` from a raw pointer.
You can’t perform that action at this time.
0 commit comments