From aa4a9b0827f09efa8a06d99df6cae07b21e6729c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 22 Feb 2019 22:58:53 +0100 Subject: [PATCH] make MaybeUninit Copy --- src/libcore/mem.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 8f6798e0f6e61..296f15d830302 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -1106,12 +1106,22 @@ impl DerefMut for ManuallyDrop { // 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 { uninit: (), value: ManuallyDrop, } +#[unstable(feature = "maybe_uninit", issue = "53491")] +impl Clone for MaybeUninit { + #[inline(always)] + fn clone(&self) -> Self { + // Not calling T::clone(), we cannot know if we are initialized enough for that. + *self + } +} + impl MaybeUninit { /// Create a new `MaybeUninit` initialized with the given value. ///