Skip to content

Commit a79b912

Browse files
authored
Rollup merge of rust-lang#55252 - SimonSapin:maybeuninit-new, r=bluss
Add MaybeUninit::new Sometimes it *is* initialized!
2 parents 409382e + ac18635 commit a79b912

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#![feature(const_fn)]
8383
#![feature(const_int_ops)]
8484
#![feature(const_fn_union)]
85+
#![feature(const_manually_drop_new)]
8586
#![feature(custom_attribute)]
8687
#![feature(doc_cfg)]
8788
#![feature(doc_spotlight)]

src/libcore/mem.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,15 @@ pub union MaybeUninit<T> {
10211021
}
10221022

10231023
impl<T> MaybeUninit<T> {
1024+
/// Create a new `MaybeUninit` initialized with the given value.
1025+
///
1026+
/// Note that dropping a `MaybeUninit` will never call `T`'s drop code.
1027+
/// It is your responsibility to make sure `T` gets dropped if it got initialized.
1028+
#[unstable(feature = "maybe_uninit", issue = "53491")]
1029+
pub const fn new(val: T) -> MaybeUninit<T> {
1030+
MaybeUninit { value: ManuallyDrop::new(val) }
1031+
}
1032+
10241033
/// Create a new `MaybeUninit` in an uninitialized state.
10251034
///
10261035
/// Note that dropping a `MaybeUninit` will never call `T`'s drop code.

0 commit comments

Comments
 (0)