]>
git.proxmox.com Git - rustc.git/blob - library/alloc/tests/boxed.rs
2 use std
::mem
::MaybeUninit
;
6 fn unitialized_zero_size_box() {
8 &*Box
::<()>::new_uninit() as *const _
,
9 NonNull
::<MaybeUninit
<()>>::dangling().as_ptr(),
12 Box
::<[()]>::new_uninit_slice(4).as_ptr(),
13 NonNull
::<MaybeUninit
<()>>::dangling().as_ptr(),
16 Box
::<[String
]>::new_uninit_slice(0).as_ptr(),
17 NonNull
::<MaybeUninit
<String
>>::dangling().as_ptr(),
21 #[derive(Clone, PartialEq, Eq, Debug)]
27 fn box_clone_and_clone_from_equivalence() {
28 for size
in (0..8).map(|i
| 2usize
.pow(i
)) {
29 let control
= vec
![Dummy { _data: 42 }
; size
].into_boxed_slice();
30 let clone
= control
.clone();
31 let mut copy
= vec
![Dummy { _data: 84 }
; size
].into_boxed_slice();
32 copy
.clone_from(&control
);
33 assert_eq
!(control
, clone
);
34 assert_eq
!(control
, copy
);
38 /// This test might give a false positive in case the box realocates, but the alocator keeps the
41 /// On the other hand it won't give a false negative, if it fails than the memory was definitely not
44 fn box_clone_from_ptr_stability() {
45 for size
in (0..8).map(|i
| 2usize
.pow(i
)) {
46 let control
= vec
![Dummy { _data: 42 }
; size
].into_boxed_slice();
47 let mut copy
= vec
![Dummy { _data: 84 }
; size
].into_boxed_slice();
48 let copy_raw
= copy
.as_ptr() as usize;
49 copy
.clone_from(&control
);
50 assert_eq
!(copy
.as_ptr() as usize, copy_raw
);
56 let x
= Box
::new(Cell
::new(5));
58 assert_eq
!(x
.get(), 1000);