@@ -907,8 +907,7 @@ impl<T: ?Sized> Rc<T> {
907
907
let offset = unsafe { data_offset ( ptr) } ;
908
908
909
909
// Reverse the offset to find the original RcBox.
910
- let rc_ptr =
911
- unsafe { ( ptr as * mut u8 ) . offset ( -offset) . with_metadata_of ( ptr as * mut RcBox < T > ) } ;
910
+ let rc_ptr = unsafe { ptr. byte_sub ( offset) as * mut RcBox < T > } ;
912
911
913
912
unsafe { Self :: from_ptr ( rc_ptr) }
914
913
}
@@ -2331,7 +2330,7 @@ impl<T: ?Sized> Weak<T> {
2331
2330
let offset = unsafe { data_offset ( ptr) } ;
2332
2331
// Thus, we reverse the offset to get the whole RcBox.
2333
2332
// SAFETY: the pointer originated from a Weak, so this offset is safe.
2334
- unsafe { ( ptr as * mut u8 ) . offset ( - offset) . with_metadata_of ( ptr as * mut RcBox < T > ) }
2333
+ unsafe { ptr. byte_sub ( offset) as * mut RcBox < T > }
2335
2334
} ;
2336
2335
2337
2336
// SAFETY: we now have recovered the original Weak pointer, so can create the Weak.
@@ -2684,7 +2683,7 @@ impl<T: ?Sized> Unpin for Rc<T> {}
2684
2683
///
2685
2684
/// The pointer must point to (and have valid metadata for) a previously
2686
2685
/// valid instance of T, but the T is allowed to be dropped.
2687
- unsafe fn data_offset < T : ?Sized > ( ptr : * const T ) -> isize {
2686
+ unsafe fn data_offset < T : ?Sized > ( ptr : * const T ) -> usize {
2688
2687
// Align the unsized value to the end of the RcBox.
2689
2688
// Because RcBox is repr(C), it will always be the last field in memory.
2690
2689
// SAFETY: since the only unsized types possible are slices, trait objects,
@@ -2695,7 +2694,7 @@ unsafe fn data_offset<T: ?Sized>(ptr: *const T) -> isize {
2695
2694
}
2696
2695
2697
2696
#[ inline]
2698
- fn data_offset_align ( align : usize ) -> isize {
2697
+ fn data_offset_align ( align : usize ) -> usize {
2699
2698
let layout = Layout :: new :: < RcBox < ( ) > > ( ) ;
2700
- ( layout. size ( ) + layout. padding_needed_for ( align) ) as isize
2699
+ layout. size ( ) + layout. padding_needed_for ( align)
2701
2700
}
0 commit comments