From 227db40a98e5bd903aa3658c16f19a3d6f694deb Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 16 Oct 2019 20:33:55 +0200 Subject: [PATCH] Uninitialized boxes: add test for zero-size allocations --- src/liballoc/tests/boxed.rs | 18 ++++++++++++++++++ src/liballoc/tests/lib.rs | 2 ++ 2 files changed, 20 insertions(+) create mode 100644 src/liballoc/tests/boxed.rs diff --git a/src/liballoc/tests/boxed.rs b/src/liballoc/tests/boxed.rs new file mode 100644 index 0000000000000..bc3d53bf30da3 --- /dev/null +++ b/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::>::dangling().as_ptr(), + ); + assert_eq!( + Box::<[()]>::new_uninit_slice(4).as_ptr(), + NonNull::>::dangling().as_ptr(), + ); + assert_eq!( + Box::<[String]>::new_uninit_slice(0).as_ptr(), + NonNull::>::dangling().as_ptr(), + ); +} diff --git a/src/liballoc/tests/lib.rs b/src/liballoc/tests/lib.rs index 5723a30c0f34f..59f5c8dfb8a87 100644 --- a/src/liballoc/tests/lib.rs +++ b/src/liballoc/tests/lib.rs @@ -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;