]> git.lizzy.rs Git - rust.git/commitdiff
Add MaybeUninit::new
authorSimon Sapin <simon.sapin@exyr.org>
Sun, 21 Oct 2018 21:54:35 +0000 (23:54 +0200)
committerSimon Sapin <simon.sapin@exyr.org>
Sun, 21 Oct 2018 21:56:09 +0000 (23:56 +0200)
Sometimes it *is* initialized!

src/libcore/lib.rs
src/libcore/mem.rs

index 59cc312bee5fcc4064751bca256ed75592fa31ea..1eded42683073481889a61a9d1d3cd7131318b15 100644 (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)]
index 27ee9556bd0895dbe2ccd6e903812a57d3e721df..a955e0e662a6c4e2545067357c148f48009c461f 100644 (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.