This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 1818#![ feature( const_eval_select) ]
1919#![ feature( const_heap) ]
2020#![ feature( const_nonnull_new) ]
21+ #![ feature( const_swap) ]
2122#![ feature( const_trait_impl) ]
2223#![ feature( core_intrinsics) ]
2324#![ feature( core_io_borrowed_buf) ]
Original file line number Diff line number Diff line change @@ -897,6 +897,25 @@ fn test_const_copy() {
897897 } ;
898898}
899899
900+ #[ test]
901+ fn test_const_swap ( ) {
902+ const {
903+ let mut ptr1 = & 1 ;
904+ let mut ptr2 = & 666 ;
905+
906+ // Swap ptr1 and ptr2, bytewise. `swap` does not take a count
907+ // so the best we can do is use an array.
908+ type T = [ u8 ; mem:: size_of :: < & i32 > ( ) ] ;
909+ unsafe {
910+ ptr:: swap ( ptr:: from_mut ( & mut ptr1) . cast :: < T > ( ) , ptr:: from_mut ( & mut ptr2) . cast :: < T > ( ) ) ;
911+ }
912+
913+ // Make sure they still work.
914+ assert ! ( * ptr1 == 666 ) ;
915+ assert ! ( * ptr2 == 1 ) ;
916+ } ;
917+ }
918+
900919#[ test]
901920fn test_null_array_as_slice ( ) {
902921 let arr: * mut [ u8 ; 4 ] = null_mut ( ) ;
Original file line number Diff line number Diff line change 11//@ compile-flags: -Z ui-testing=no
22
33
4- #![ feature( const_swap ) ]
4+ #![ feature( const_swap_nonoverlapping ) ]
55use std:: {
66 mem:: { self , MaybeUninit } ,
77 ptr,
You can’t perform that action at this time.
0 commit comments