]> git.lizzy.rs Git - rust.git/commitdiff
make MaybeUninit Copy
authorRalf Jung <post@ralfj.de>
Fri, 22 Feb 2019 21:58:53 +0000 (22:58 +0100)
committerRalf Jung <post@ralfj.de>
Fri, 22 Feb 2019 22:06:03 +0000 (23:06 +0100)
src/libcore/mem.rs

index 8f6798e0f6e61f46e461882defc7a5a1507ecda9..296f15d83030201eccf3b657dbbab351acf09256 100644 (file)
@@ -1106,12 +1106,22 @@ fn deref_mut(&mut self) -> &mut 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.
     ///