test const_copy to make sure bytewise pointer copies are working
This commit is contained in:
parent
72f7e3144a
commit
4990021082
@ -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)]
|
||||
|
@ -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 @@ pub fn set_tag(&mut self, data: usize) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[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);
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user