diff options
| author | Ralf Jung <post@ralfj.de> | 2022-06-03 09:18:33 -0400 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2022-06-03 09:20:42 -0400 |
| commit | 4990021082b329d628134e42d65680f4e7195b3b (patch) | |
| tree | a47a2ae6970501e00b39e2d8c1dcfea03e34f1a8 | |
| parent | 72f7e3144a386c820c188350092d2d93a74889b8 (diff) | |
| download | rust-4990021082b329d628134e42d65680f4e7195b3b.tar.gz rust-4990021082b329d628134e42d65680f4e7195b3b.zip | |
test const_copy to make sure bytewise pointer copies are working
| -rw-r--r-- | library/core/tests/lib.rs | 1 | ||||
| -rw-r--r-- | library/core/tests/ptr.rs | 40 |
2 files changed, 41 insertions, 0 deletions
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 7e9d7d27101..9505ec31609 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -84,6 +84,7 @@ #![feature(const_option)] #![feature(const_option_ext)] #![feature(const_result)] +#![feature(const_intrinsic_copy)] #![feature(integer_atomics)] #![feature(int_roundings)] #![feature(slice_group_by)] diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index c5242ad04de..40b2b49bdbd 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -1,4 +1,5 @@ use core::cell::RefCell; +use core::mem::{self, MaybeUninit}; use core::num::NonZeroUsize; use core::ptr; use core::ptr::*; @@ -781,3 +782,42 @@ fn nonnull_tagged_pointer_with_provenance() { } } } + +#[test] +fn test_const_copy() { + const { + let ptr1 = &1; + let mut ptr2 = &666; + + // Copy ptr1 to ptr2, bytewise. + unsafe { + ptr::copy( + &ptr1 as *const _ as *const MaybeUninit<u8>, + &mut ptr2 as *mut _ as *mut MaybeUninit<u8>, + mem::size_of::<&i32>(), + ); + } + + // Make sure they still work. + assert!(*ptr1 == 1); + assert!(*ptr2 == 1); + }; + + const { + let ptr1 = &1; + let mut ptr2 = &666; + + // Copy ptr1 to ptr2, bytewise. + unsafe { + ptr::copy_nonoverlapping( + &ptr1 as *const _ as *const MaybeUninit<u8>, + &mut ptr2 as *mut _ as *mut MaybeUninit<u8>, + mem::size_of::<&i32>(), + ); + } + + // Make sure they still work. + assert!(*ptr1 == 1); + assert!(*ptr2 == 1); + }; +} |
