diff options
| author | Lance Roy <ldr709@gmail.com> | 2017-09-04 02:29:16 -0700 |
|---|---|---|
| committer | Lance Roy <ldr709@gmail.com> | 2017-09-04 02:29:16 -0700 |
| commit | 94301c405c5382c482a4bc5fc2561257418f9323 (patch) | |
| tree | bd6d17070280f26b68506b9e67bf6e39621368a5 | |
| parent | 6276dbd9533e05bd577f408047ea1d0e97293217 (diff) | |
| download | rust-94301c405c5382c482a4bc5fc2561257418f9323.tar.gz rust-94301c405c5382c482a4bc5fc2561257418f9323.zip | |
Additional traits for std::mem::ManuallyDrop
Add pass-through implementations for all of the derivable traits. These cannot be derived since ManuallyDrop is a union.
| -rw-r--r-- | src/libcore/mem.rs | 65 |
1 files changed, 61 insertions, 4 deletions
diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 4cc0a5e49d9..af2f876a2f3 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; @@ -871,7 +872,7 @@ impl<T> ManuallyDrop<T> { } #[stable(feature = "manually_drop", since = "1.20.0")] -impl<T> ::ops::Deref for ManuallyDrop<T> { +impl<T> Deref for ManuallyDrop<T> { type Target = T; #[inline] fn deref(&self) -> &Self::Target { @@ -882,7 +883,7 @@ impl<T> ::ops::Deref for ManuallyDrop<T> { } #[stable(feature = "manually_drop", since = "1.20.0")] -impl<T> ::ops::DerefMut for ManuallyDrop<T> { +impl<T> DerefMut for ManuallyDrop<T> { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { unsafe { @@ -903,16 +904,72 @@ 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); } } +#[stable(feature = "manually_drop", since = "1.20.0")] +impl<T: Default> Default for ManuallyDrop<T> { + fn default() -> Self { + ManuallyDrop::new(Default::default()) + } +} + +#[stable(feature = "manually_drop", since = "1.20.0")] +impl<T: PartialEq> PartialEq for ManuallyDrop<T> { + 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<T: Eq> Eq for ManuallyDrop<T> {} + +#[stable(feature = "manually_drop", since = "1.20.0")] +impl<T: PartialOrd> PartialOrd for ManuallyDrop<T> { + 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<T: Ord> Ord for ManuallyDrop<T> { + fn cmp(&self, other: &Self) -> ::cmp::Ordering { + self.deref().cmp(other) + } +} + +#[stable(feature = "manually_drop", since = "1.20.0")] +impl<T: ::hash::Hash> ::hash::Hash for ManuallyDrop<T> { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + self.deref().hash(state); + } +} + /// Tells LLVM that this point in the code is not reachable, enabling further /// optimizations. /// |
