Skip to content

Commit 352b026

Browse files
committed
Uninitialized boxes: add test for zero-size allocations
1 parent ca1cfda commit 352b026

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/liballoc/tests/boxed.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use std::ptr::NonNull;
2+
use std::mem::MaybeUninit;
3+
4+
#[test]
5+
fn unitialized_zero_size_box() {
6+
assert_eq!(
7+
&*Box::<()>::new_uninit() as *const _,
8+
NonNull::<MaybeUninit<()>>::dangling().as_ptr(),
9+
);
10+
assert_eq!(
11+
Box::<[()]>::new_uninit_slice(4).as_ptr(),
12+
NonNull::<MaybeUninit<()>>::dangling().as_ptr(),
13+
);
14+
assert_eq!(
15+
Box::<[String]>::new_uninit_slice(0).as_ptr(),
16+
NonNull::<MaybeUninit<String>>::dangling().as_ptr(),
17+
);
18+
}
19+

src/liballoc/tests/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![feature(box_syntax)]
33
#![feature(drain_filter)]
44
#![feature(exact_size_is_empty)]
5+
#![feature(new_uninit)]
56
#![feature(option_flattening)]
67
#![feature(pattern)]
78
#![feature(repeat_generic_slice)]
@@ -15,6 +16,7 @@ use std::collections::hash_map::DefaultHasher;
1516

1617
mod arc;
1718
mod binary_heap;
19+
mod boxed;
1820
mod btree;
1921
mod cow_str;
2022
mod fmt;

0 commit comments

Comments
 (0)