about summary refs log tree commit diff
path: root/tests/ui/allocator/empty-alloc-nonnull-guarantee.rs
blob: f4081306c77fc5696c0664c691ef8c191ce20584 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! Check that the default global Rust allocator produces non-null Box allocations for ZSTs.
//!
//! See https://github.com/rust-lang/rust/issues/11998

//@ run-pass

pub fn main() {
    assert!(Some(Box::new(())).is_some());

    let xs: Box<[()]> = Box::<[(); 0]>::new([]);
    assert!(Some(xs).is_some());

    struct Foo;
    assert!(Some(Box::new(Foo)).is_some());

    let ys: Box<[Foo]> = Box::<[Foo; 0]>::new([]);
    assert!(Some(ys).is_some());
}