Skip to content

Commit

Permalink
Uninitialized boxes: add test for zero-size allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Oct 18, 2019
1 parent ca1cfda commit 227db40
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/liballoc/tests/boxed.rs
@@ -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(),
);
}
2 changes: 2 additions & 0 deletions src/liballoc/tests/lib.rs
Expand Up @@ -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)]
Expand All @@ -15,6 +16,7 @@ use std::collections::hash_map::DefaultHasher;

mod arc;
mod binary_heap;
mod boxed;
mod btree;
mod cow_str;
mod fmt;
Expand Down

0 comments on commit 227db40

Please sign in to comment.