@@ -487,8 +487,7 @@ impl<T: ?Sized> *mut T {
487
487
#[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
488
488
pub const unsafe fn byte_offset ( self , count : isize ) -> Self {
489
489
// 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 ) }
492
491
}
493
492
494
493
/// Calculates the offset from a pointer using wrapping arithmetic.
@@ -567,10 +566,7 @@ impl<T: ?Sized> *mut T {
567
566
#[ unstable( feature = "pointer_byte_offsets" , issue = "96283" ) ]
568
567
#[ rustc_const_unstable( feature = "const_pointer_byte_offsets" , issue = "96283" ) ]
569
568
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 )
574
570
}
575
571
576
572
/// Masks out bits of the pointer according to a mask.
@@ -583,8 +579,7 @@ impl<T: ?Sized> *mut T {
583
579
#[ must_use = "returns a new pointer rather than modifying its argument" ]
584
580
#[ inline( always) ]
585
581
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 )
588
583
}
589
584
590
585
/// Returns `None` if the pointer is null, or else returns a unique reference to
@@ -1011,8 +1006,7 @@ impl<T: ?Sized> *mut T {
1011
1006
#[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
1012
1007
pub const unsafe fn byte_add ( self , count : usize ) -> Self {
1013
1008
// 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 ) }
1016
1010
}
1017
1011
1018
1012
/// Calculates the offset from a pointer (convenience for
@@ -1098,8 +1092,7 @@ impl<T: ?Sized> *mut T {
1098
1092
#[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
1099
1093
pub const unsafe fn byte_sub ( self , count : usize ) -> Self {
1100
1094
// 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 ) }
1103
1096
}
1104
1097
1105
1098
/// Calculates the offset from a pointer using wrapping arithmetic.
@@ -1179,7 +1172,7 @@ impl<T: ?Sized> *mut T {
1179
1172
#[ unstable( feature = "pointer_byte_offsets" , issue = "96283" ) ]
1180
1173
#[ rustc_const_unstable( feature = "const_pointer_byte_offsets" , issue = "96283" ) ]
1181
1174
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 )
1183
1176
}
1184
1177
1185
1178
/// Calculates the offset from a pointer using wrapping arithmetic.
@@ -1259,7 +1252,7 @@ impl<T: ?Sized> *mut T {
1259
1252
#[ unstable( feature = "pointer_byte_offsets" , issue = "96283" ) ]
1260
1253
#[ rustc_const_unstable( feature = "const_pointer_byte_offsets" , issue = "96283" ) ]
1261
1254
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 )
1263
1256
}
1264
1257
1265
1258
/// Reads the value from `self` without moving it. This leaves the
0 commit comments