File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 8484#![ feature( const_option) ]
8585#![ feature( const_option_ext) ]
8686#![ feature( const_result) ]
87+ #![ feature( const_intrinsic_copy) ]
8788#![ feature( integer_atomics) ]
8889#![ feature( int_roundings) ]
8990#![ feature( slice_group_by) ]
Original file line number Diff line number Diff line change 11use core:: cell:: RefCell ;
2+ use core:: mem:: { self , MaybeUninit } ;
23use core:: num:: NonZeroUsize ;
34use core:: ptr;
45use core:: ptr:: * ;
@@ -781,3 +782,42 @@ fn nonnull_tagged_pointer_with_provenance() {
781782 }
782783 }
783784}
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