File tree 2 files changed +20
-0
lines changed
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 18
18
#![ feature( const_eval_select) ]
19
19
#![ feature( const_heap) ]
20
20
#![ feature( const_nonnull_new) ]
21
+ #![ feature( const_swap) ]
21
22
#![ feature( const_trait_impl) ]
22
23
#![ feature( core_intrinsics) ]
23
24
#![ feature( core_io_borrowed_buf) ]
Original file line number Diff line number Diff line change @@ -897,6 +897,25 @@ fn test_const_copy() {
897
897
} ;
898
898
}
899
899
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
+
900
919
#[ test]
901
920
fn test_null_array_as_slice ( ) {
902
921
let arr: * mut [ u8 ; 4 ] = null_mut ( ) ;
You can’t perform that action at this time.
0 commit comments