use a const to hack around promotion limitations

This commit is contained in:
Ralf Jung 2019-07-21 12:02:28 +02:00
parent ad261f6852
commit 4b47e78a16
3 changed files with 10 additions and 2 deletions

View file

@ -85,6 +85,7 @@
#![feature(fmt_internals)]
#![feature(fn_traits)]
#![feature(fundamental)]
#![feature(internal_uninit_const)]
#![feature(lang_items)]
#![feature(libc)]
#![feature(nll)]

View file

@ -653,7 +653,7 @@ macro_rules! uninit_array {
#[cfg(not(bootstrap))]
macro_rules! uninit_array {
($t:ty; $size:expr) => (
[MaybeUninit::<$t>::uninit(); $size]
[MaybeUninit::<$t>::UNINIT; $size]
);
}

View file

@ -248,11 +248,18 @@ impl<T> MaybeUninit<T> {
/// [type]: union.MaybeUninit.html
#[stable(feature = "maybe_uninit", since = "1.36.0")]
#[inline(always)]
#[rustc_promotable]
pub const fn uninit() -> MaybeUninit<T> {
MaybeUninit { uninit: () }
}
/// A promotable constant, equivalent to `uninit()`.
#[unstable(
feature = "internal_uninit_const",
issue = "0",
reason = "hack to work around promotability",
)]
pub const UNINIT: Self = Self::uninit();
/// Creates a new `MaybeUninit<T>` in an uninitialized state, with the memory being
/// filled with `0` bytes. It depends on `T` whether that already makes for
/// proper initialization. For example, `MaybeUninit<usize>::zeroed()` is initialized,