1 use std::mem::MaybeUninit;
5 fn unitialized_zero_size_box() {
7 &*Box::<()>::new_uninit() as *const _,
8 NonNull::<MaybeUninit<()>>::dangling().as_ptr(),
11 Box::<[()]>::new_uninit_slice(4).as_ptr(),
12 NonNull::<MaybeUninit<()>>::dangling().as_ptr(),
15 Box::<[String]>::new_uninit_slice(0).as_ptr(),
16 NonNull::<MaybeUninit<String>>::dangling().as_ptr(),
20 #[derive(Clone, PartialEq, Eq, Debug)]
26 fn box_clone_and_clone_from_equivalence() {
27 for size in (0..8).map(|i| 2usize.pow(i)) {
28 let control = vec![Dummy { _data: 42 }; size].into_boxed_slice();
29 let clone = control.clone();
30 let mut copy = vec![Dummy { _data: 84 }; size].into_boxed_slice();
31 copy.clone_from(&control);
32 assert_eq!(control, clone);
33 assert_eq!(control, copy);
37 /// This test might give a false positive in case the box realocates, but the alocator keeps the
40 /// On the other hand it won't give a false negative, if it fails than the memory was definitely not
43 fn box_clone_from_ptr_stability() {
44 for size in (0..8).map(|i| 2usize.pow(i)) {
45 let control = vec![Dummy { _data: 42 }; size].into_boxed_slice();
46 let mut copy = vec![Dummy { _data: 84 }; size].into_boxed_slice();
47 let copy_raw = copy.as_ptr() as usize;
48 copy.clone_from(&control);
49 assert_eq!(copy.as_ptr() as usize, copy_raw);