From 6276dbd9533e05bd577f408047ea1d0e97293217 Mon Sep 17 00:00:00 2001 From: Lance Roy Date: Sun, 3 Sep 2017 23:27:20 -0700 Subject: [PATCH] Derive std::mem::ManuallyDrop from Clone and Copy. Although types that don't implement Drop can't be Copyable, this can still be useful when ManuallyDrop is used inside a generic type. This doesn't derive from Copy as that would require T: Copy + Clone, instead it provides an impl of Clone for T: Clone. --- src/libcore/mem.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index a57d83552898..4cc0a5e49d94 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -821,6 +821,7 @@ pub fn discriminant(v: &T) -> Discriminant { /// ``` #[stable(feature = "manually_drop", since = "1.20.0")] #[allow(unions_with_drop_fields)] +#[derive(Copy)] pub union ManuallyDrop{ value: T } impl ManuallyDrop { @@ -899,6 +900,19 @@ impl ::fmt::Debug for ManuallyDrop { } } +#[stable(feature = "manually_drop", since = "1.20.0")] +impl Clone for ManuallyDrop { + fn clone(&self) -> Self { + use ::ops::Deref; + ManuallyDrop::new(self.deref().clone()) + } + + fn clone_from(&mut self, source: &Self) { + use ::ops::DerefMut; + self.deref_mut().clone_from(source); + } +} + /// Tells LLVM that this point in the code is not reachable, enabling further /// optimizations. ///