about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2019-02-22 22:58:53 +0100
committerRalf Jung <post@ralfj.de>2019-02-22 23:06:03 +0100
commitaa4a9b0827f09efa8a06d99df6cae07b21e6729c (patch)
treedf99f965d3d5837049c8c9871ca551c0bb05b5f6
parentd10366fe27bf1a1e6ab67076bdc268f486abeb88 (diff)
downloadrust-aa4a9b0827f09efa8a06d99df6cae07b21e6729c.tar.gz
rust-aa4a9b0827f09efa8a06d99df6cae07b21e6729c.zip
make MaybeUninit Copy
-rw-r--r--src/libcore/mem.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs
index 8f6798e0f6e..296f15d8303 100644
--- a/src/libcore/mem.rs
+++ b/src/libcore/mem.rs
@@ -1106,12 +1106,22 @@ impl<T: ?Sized> DerefMut for ManuallyDrop<T> {
 // FIXME before stabilizing, explain how to initialize a struct field-by-field.
 #[allow(missing_debug_implementations)]
 #[unstable(feature = "maybe_uninit", issue = "53491")]
+#[derive(Copy)]
 // NOTE after stabilizing `MaybeUninit` proceed to deprecate `mem::uninitialized`
 pub union MaybeUninit<T> {
     uninit: (),
     value: ManuallyDrop<T>,
 }
 
+#[unstable(feature = "maybe_uninit", issue = "53491")]
+impl<T: Copy> Clone for MaybeUninit<T> {
+    #[inline(always)]
+    fn clone(&self) -> Self {
+        // Not calling T::clone(), we cannot know if we are initialized enough for that.
+        *self
+    }
+}
+
 impl<T> MaybeUninit<T> {
     /// Create a new `MaybeUninit` initialized with the given value.
     ///