@@ -487,8 +487,7 @@ impl<T: ?Sized> *mut T {
487487 #[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
488488 pub const unsafe fn byte_offset ( self , count : isize ) -> Self {
489489 // SAFETY: the caller must uphold the safety contract for `offset`.
490- let this = unsafe { self . cast :: < u8 > ( ) . offset ( count) . cast :: < ( ) > ( ) } ;
491- from_raw_parts_mut :: < T > ( this, metadata ( self ) )
490+ unsafe { self . cast :: < u8 > ( ) . offset ( count) . with_metadata_of ( self ) }
492491 }
493492
494493 /// Calculates the offset from a pointer using wrapping arithmetic.
@@ -567,10 +566,7 @@ impl<T: ?Sized> *mut T {
567566 #[ unstable( feature = "pointer_byte_offsets" , issue = "96283" ) ]
568567 #[ rustc_const_unstable( feature = "const_pointer_byte_offsets" , issue = "96283" ) ]
569568 pub const fn wrapping_byte_offset ( self , count : isize ) -> Self {
570- from_raw_parts_mut :: < T > (
571- self . cast :: < u8 > ( ) . wrapping_offset ( count) . cast :: < ( ) > ( ) ,
572- metadata ( self ) ,
573- )
569+ self . cast :: < u8 > ( ) . wrapping_offset ( count) . with_metadata_of ( self )
574570 }
575571
576572 /// Masks out bits of the pointer according to a mask.
@@ -583,8 +579,7 @@ impl<T: ?Sized> *mut T {
583579 #[ must_use = "returns a new pointer rather than modifying its argument" ]
584580 #[ inline( always) ]
585581 pub fn mask ( self , mask : usize ) -> * mut T {
586- let this = intrinsics:: ptr_mask ( self . cast :: < ( ) > ( ) , mask) as * mut ( ) ;
587- from_raw_parts_mut :: < T > ( this, metadata ( self ) )
582+ intrinsics:: ptr_mask ( self . cast :: < ( ) > ( ) , mask) . cast_mut ( ) . with_metadata_of ( self )
588583 }
589584
590585 /// Returns `None` if the pointer is null, or else returns a unique reference to
@@ -1011,8 +1006,7 @@ impl<T: ?Sized> *mut T {
10111006 #[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
10121007 pub const unsafe fn byte_add ( self , count : usize ) -> Self {
10131008 // SAFETY: the caller must uphold the safety contract for `add`.
1014- let this = unsafe { self . cast :: < u8 > ( ) . add ( count) . cast :: < ( ) > ( ) } ;
1015- from_raw_parts_mut :: < T > ( this, metadata ( self ) )
1009+ unsafe { self . cast :: < u8 > ( ) . add ( count) . with_metadata_of ( self ) }
10161010 }
10171011
10181012 /// Calculates the offset from a pointer (convenience for
@@ -1098,8 +1092,7 @@ impl<T: ?Sized> *mut T {
10981092 #[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
10991093 pub const unsafe fn byte_sub ( self , count : usize ) -> Self {
11001094 // SAFETY: the caller must uphold the safety contract for `sub`.
1101- let this = unsafe { self . cast :: < u8 > ( ) . sub ( count) . cast :: < ( ) > ( ) } ;
1102- from_raw_parts_mut :: < T > ( this, metadata ( self ) )
1095+ unsafe { self . cast :: < u8 > ( ) . sub ( count) . with_metadata_of ( self ) }
11031096 }
11041097
11051098 /// Calculates the offset from a pointer using wrapping arithmetic.
@@ -1179,7 +1172,7 @@ impl<T: ?Sized> *mut T {
11791172 #[ unstable( feature = "pointer_byte_offsets" , issue = "96283" ) ]
11801173 #[ rustc_const_unstable( feature = "const_pointer_byte_offsets" , issue = "96283" ) ]
11811174 pub const fn wrapping_byte_add ( self , count : usize ) -> Self {
1182- from_raw_parts_mut :: < T > ( self . cast :: < u8 > ( ) . wrapping_add ( count) . cast :: < ( ) > ( ) , metadata ( self ) )
1175+ self . cast :: < u8 > ( ) . wrapping_add ( count) . with_metadata_of ( self )
11831176 }
11841177
11851178 /// Calculates the offset from a pointer using wrapping arithmetic.
@@ -1259,7 +1252,7 @@ impl<T: ?Sized> *mut T {
12591252 #[ unstable( feature = "pointer_byte_offsets" , issue = "96283" ) ]
12601253 #[ rustc_const_unstable( feature = "const_pointer_byte_offsets" , issue = "96283" ) ]
12611254 pub const fn wrapping_byte_sub ( self , count : usize ) -> Self {
1262- from_raw_parts_mut :: < T > ( self . cast :: < u8 > ( ) . wrapping_sub ( count) . cast :: < ( ) > ( ) , metadata ( self ) )
1255+ self . cast :: < u8 > ( ) . wrapping_sub ( count) . with_metadata_of ( self )
12631256 }
12641257
12651258 /// Reads the value from `self` without moving it. This leaves the
0 commit comments