Uninitialized boxes: add test for zero-size allocations

This commit is contained in:
Simon Sapin 2019-10-16 20:33:55 +02:00
parent ca1cfdab78
commit 227db40a98
2 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,18 @@
use std::ptr::NonNull;
use std::mem::MaybeUninit;
#[test]
fn unitialized_zero_size_box() {
assert_eq!(
&*Box::<()>::new_uninit() as *const _,
NonNull::<MaybeUninit<()>>::dangling().as_ptr(),
);
assert_eq!(
Box::<[()]>::new_uninit_slice(4).as_ptr(),
NonNull::<MaybeUninit<()>>::dangling().as_ptr(),
);
assert_eq!(
Box::<[String]>::new_uninit_slice(0).as_ptr(),
NonNull::<MaybeUninit<String>>::dangling().as_ptr(),
);
}

View File

@ -2,6 +2,7 @@
#![feature(box_syntax)]
#![feature(drain_filter)]
#![feature(exact_size_is_empty)]
#![feature(new_uninit)]
#![feature(option_flattening)]
#![feature(pattern)]
#![feature(repeat_generic_slice)]
@ -15,6 +16,7 @@ use std::collections::hash_map::DefaultHasher;
mod arc;
mod binary_heap;
mod boxed;
mod btree;
mod cow_str;
mod fmt;