diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index a57d835528980..af2f876a2f359 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -22,6 +22,7 @@ use hash; use intrinsics; use marker::{Copy, PhantomData, Sized}; use ptr; +use ops::{Deref, DerefMut}; #[stable(feature = "rust1", since = "1.0.0")] pub use intrinsics::transmute; @@ -821,6 +822,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 { @@ -870,7 +872,7 @@ impl ManuallyDrop { } #[stable(feature = "manually_drop", since = "1.20.0")] -impl ::ops::Deref for ManuallyDrop { +impl Deref for ManuallyDrop { type Target = T; #[inline] fn deref(&self) -> &Self::Target { @@ -881,7 +883,7 @@ impl ::ops::Deref for ManuallyDrop { } #[stable(feature = "manually_drop", since = "1.20.0")] -impl ::ops::DerefMut for ManuallyDrop { +impl DerefMut for ManuallyDrop { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { unsafe { @@ -899,6 +901,75 @@ impl ::fmt::Debug for ManuallyDrop { } } +#[stable(feature = "manually_drop", since = "1.20.0")] +impl Clone for ManuallyDrop { + fn clone(&self) -> Self { + ManuallyDrop::new(self.deref().clone()) + } + + fn clone_from(&mut self, source: &Self) { + self.deref_mut().clone_from(source); + } +} + +#[stable(feature = "manually_drop", since = "1.20.0")] +impl Default for ManuallyDrop { + fn default() -> Self { + ManuallyDrop::new(Default::default()) + } +} + +#[stable(feature = "manually_drop", since = "1.20.0")] +impl PartialEq for ManuallyDrop { + fn eq(&self, other: &Self) -> bool { + self.deref().eq(other) + } + + fn ne(&self, other: &Self) -> bool { + self.deref().ne(other) + } +} + +#[stable(feature = "manually_drop", since = "1.20.0")] +impl Eq for ManuallyDrop {} + +#[stable(feature = "manually_drop", since = "1.20.0")] +impl PartialOrd for ManuallyDrop { + fn partial_cmp(&self, other: &Self) -> Option<::cmp::Ordering> { + self.deref().partial_cmp(other) + } + + fn lt(&self, other: &Self) -> bool { + self.deref().lt(other) + } + + fn le(&self, other: &Self) -> bool { + self.deref().le(other) + } + + fn gt(&self, other: &Self) -> bool { + self.deref().gt(other) + } + + fn ge(&self, other: &Self) -> bool { + self.deref().ge(other) + } +} + +#[stable(feature = "manually_drop", since = "1.20.0")] +impl Ord for ManuallyDrop { + fn cmp(&self, other: &Self) -> ::cmp::Ordering { + self.deref().cmp(other) + } +} + +#[stable(feature = "manually_drop", since = "1.20.0")] +impl ::hash::Hash for ManuallyDrop { + fn hash(&self, state: &mut H) { + self.deref().hash(state); + } +} + /// Tells LLVM that this point in the code is not reachable, enabling further /// optimizations. ///