Rollup merge of #55252 - SimonSapin:maybeuninit-new, r=bluss

Add MaybeUninit::new

Sometimes it *is* initialized!
This commit is contained in:
kennytm 2018-10-28 16:38:48 +08:00 committed by GitHub
commit a79b91231e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -82,6 +82,7 @@
#![feature(const_fn)]
#![feature(const_int_ops)]
#![feature(const_fn_union)]
#![feature(const_manually_drop_new)]
#![feature(custom_attribute)]
#![feature(doc_cfg)]
#![feature(doc_spotlight)]

View File

@ -1021,6 +1021,15 @@ pub union MaybeUninit<T> {
}
impl<T> MaybeUninit<T> {
/// Create a new `MaybeUninit` initialized with the given value.
///
/// Note that dropping a `MaybeUninit` will never call `T`'s drop code.
/// It is your responsibility to make sure `T` gets dropped if it got initialized.
#[unstable(feature = "maybe_uninit", issue = "53491")]
pub const fn new(val: T) -> MaybeUninit<T> {
MaybeUninit { value: ManuallyDrop::new(val) }
}
/// Create a new `MaybeUninit` in an uninitialized state.
///
/// Note that dropping a `MaybeUninit` will never call `T`'s drop code.