@@ -905,15 +905,15 @@ pub const unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) {
905
905
if mem:: align_of:: <T >( ) >= mem:: align_of:: <$ChunkTy>( )
906
906
&& mem:: size_of:: <T >( ) % mem:: size_of:: <$ChunkTy>( ) == 0
907
907
{
908
- let x: * mut MaybeUninit < $ChunkTy> = x. cast( ) ;
909
- let y: * mut MaybeUninit < $ChunkTy> = y. cast( ) ;
908
+ let x: * mut $ChunkTy = x. cast( ) ;
909
+ let y: * mut $ChunkTy = y. cast( ) ;
910
910
let count = count * ( mem:: size_of:: <T >( ) / mem:: size_of:: <$ChunkTy>( ) ) ;
911
911
// SAFETY: these are the same bytes that the caller promised were
912
912
// ok, just typed as `MaybeUninit<ChunkTy>`s instead of as `T`s.
913
913
// The `if` condition above ensures that we're not violating
914
914
// alignment requirements, and that the division is exact so
915
915
// that we don't lose any bytes off the end.
916
- return unsafe { swap_nonoverlapping_simple ( x, y, count) } ;
916
+ return unsafe { swap_nonoverlapping_simple_untyped ( x, y, count) } ;
917
917
}
918
918
} ;
919
919
}
@@ -946,7 +946,7 @@ pub const unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) {
946
946
}
947
947
948
948
// SAFETY: Same preconditions as this function
949
- unsafe { swap_nonoverlapping_simple ( x, y, count) }
949
+ unsafe { swap_nonoverlapping_simple_untyped ( x, y, count) }
950
950
}
951
951
952
952
/// Same behaviour and safety conditions as [`swap_nonoverlapping`]
@@ -955,16 +955,16 @@ pub const unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) {
955
955
/// `swap_nonoverlapping` tries to use) so no need to manually SIMD it.
956
956
#[ inline]
957
957
#[ rustc_const_unstable( feature = "const_swap" , issue = "83163" ) ]
958
- const unsafe fn swap_nonoverlapping_simple < T > ( x : * mut T , y : * mut T , count : usize ) {
958
+ const unsafe fn swap_nonoverlapping_simple_untyped < T > ( x : * mut T , y : * mut T , count : usize ) {
959
+ let x = x. cast :: < MaybeUninit < T > > ( ) ;
960
+ let y = y. cast :: < MaybeUninit < T > > ( ) ;
959
961
let mut i = 0 ;
960
962
while i < count {
961
- let x: & mut T =
962
- // SAFETY: By precondition, `i` is in-bounds because it's below `n`
963
- unsafe { & mut * x. add ( i) } ;
964
- let y: & mut T =
965
- // SAFETY: By precondition, `i` is in-bounds because it's below `n`
966
- // and it's distinct from `x` since the ranges are non-overlapping
967
- unsafe { & mut * y. add ( i) } ;
963
+ // SAFETY: By precondition, `i` is in-bounds because it's below `n`
964
+ let x = unsafe { & mut * x. add ( i) } ;
965
+ // SAFETY: By precondition, `i` is in-bounds because it's below `n`
966
+ // and it's distinct from `x` since the ranges are non-overlapping
967
+ let y = unsafe { & mut * y. add ( i) } ;
968
968
mem:: swap_simple ( x, y) ;
969
969
970
970
i += 1 ;
0 commit comments