@@ -907,8 +907,7 @@ impl<T: ?Sized> Rc<T> {
907907 let offset = unsafe { data_offset ( ptr) } ;
908908
909909 // 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 > } ;
912911
913912 unsafe { Self :: from_ptr ( rc_ptr) }
914913 }
@@ -2331,7 +2330,7 @@ impl<T: ?Sized> Weak<T> {
23312330 let offset = unsafe { data_offset ( ptr) } ;
23322331 // Thus, we reverse the offset to get the whole RcBox.
23332332 // 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 > }
23352334 } ;
23362335
23372336 // 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> {}
26842683///
26852684/// The pointer must point to (and have valid metadata for) a previously
26862685/// 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 {
26882687 // Align the unsized value to the end of the RcBox.
26892688 // Because RcBox is repr(C), it will always be the last field in memory.
26902689 // 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 {
26952694}
26962695
26972696#[ inline]
2698- fn data_offset_align ( align : usize ) -> isize {
2697+ fn data_offset_align ( align : usize ) -> usize {
26992698 let layout = Layout :: new :: < RcBox < ( ) > > ( ) ;
2700- ( layout. size ( ) + layout. padding_needed_for ( align) ) as isize
2699+ layout. size ( ) + layout. padding_needed_for ( align)
27012700}
0 commit comments