diff options
| author | Lance Roy <ldr709@gmail.com> | 2017-09-03 23:27:20 -0700 |
|---|---|---|
| committer | Lance Roy <ldr709@gmail.com> | 2017-09-04 01:00:15 -0700 |
| commit | 6276dbd9533e05bd577f408047ea1d0e97293217 (patch) | |
| tree | 64df64ac16ba0b1b7bc1ae4637bacc6b71eff960 /src/libcore | |
| parent | e22a3cf7e12b622b143694942504c66a544dc4c5 (diff) | |
| download | rust-6276dbd9533e05bd577f408047ea1d0e97293217.tar.gz rust-6276dbd9533e05bd577f408047ea1d0e97293217.zip | |
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.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/mem.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index a57d8355289..4cc0a5e49d9 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -821,6 +821,7 @@ pub fn discriminant<T>(v: &T) -> Discriminant<T> { /// ``` #[stable(feature = "manually_drop", since = "1.20.0")] #[allow(unions_with_drop_fields)] +#[derive(Copy)] pub union ManuallyDrop<T>{ value: T } impl<T> ManuallyDrop<T> { @@ -899,6 +900,19 @@ impl<T: ::fmt::Debug> ::fmt::Debug for ManuallyDrop<T> { } } +#[stable(feature = "manually_drop", since = "1.20.0")] +impl<T: Clone> Clone for ManuallyDrop<T> { + 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. /// |
