File tree 2 files changed +41
-0
lines changed
2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 84
84
#![ feature( const_option) ]
85
85
#![ feature( const_option_ext) ]
86
86
#![ feature( const_result) ]
87
+ #![ feature( const_intrinsic_copy) ]
87
88
#![ feature( integer_atomics) ]
88
89
#![ feature( int_roundings) ]
89
90
#![ feature( slice_group_by) ]
Original file line number Diff line number Diff line change 1
1
use core:: cell:: RefCell ;
2
+ use core:: mem:: { self , MaybeUninit } ;
2
3
use core:: num:: NonZeroUsize ;
3
4
use core:: ptr;
4
5
use core:: ptr:: * ;
@@ -781,3 +782,42 @@ fn nonnull_tagged_pointer_with_provenance() {
781
782
}
782
783
}
783
784
}
785
+
786
+ #[ test]
787
+ fn test_const_copy ( ) {
788
+ const {
789
+ let ptr1 = & 1 ;
790
+ let mut ptr2 = & 666 ;
791
+
792
+ // Copy ptr1 to ptr2, bytewise.
793
+ unsafe {
794
+ ptr:: copy (
795
+ & ptr1 as * const _ as * const MaybeUninit < u8 > ,
796
+ & mut ptr2 as * mut _ as * mut MaybeUninit < u8 > ,
797
+ mem:: size_of :: < & i32 > ( ) ,
798
+ ) ;
799
+ }
800
+
801
+ // Make sure they still work.
802
+ assert ! ( * ptr1 == 1 ) ;
803
+ assert ! ( * ptr2 == 1 ) ;
804
+ } ;
805
+
806
+ const {
807
+ let ptr1 = & 1 ;
808
+ let mut ptr2 = & 666 ;
809
+
810
+ // Copy ptr1 to ptr2, bytewise.
811
+ unsafe {
812
+ ptr:: copy_nonoverlapping (
813
+ & ptr1 as * const _ as * const MaybeUninit < u8 > ,
814
+ & mut ptr2 as * mut _ as * mut MaybeUninit < u8 > ,
815
+ mem:: size_of :: < & i32 > ( ) ,
816
+ ) ;
817
+ }
818
+
819
+ // Make sure they still work.
820
+ assert ! ( * ptr1 == 1 ) ;
821
+ assert ! ( * ptr2 == 1 ) ;
822
+ } ;
823
+ }
You can’t perform that action at this time.
0 commit comments