Skip to content

Commit 94301c4

Browse files
committed
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.
1 parent 6276dbd commit 94301c4

File tree

1 file changed

+61
-4
lines changed

1 file changed

+61
-4
lines changed

src/libcore/mem.rs

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use hash;
2222
use intrinsics;
2323
use marker::{Copy, PhantomData, Sized};
2424
use ptr;
25+
use ops::{Deref, DerefMut};
2526

2627
#[stable(feature = "rust1", since = "1.0.0")]
2728
pub use intrinsics::transmute;
@@ -871,7 +872,7 @@ impl<T> ManuallyDrop<T> {
871872
}
872873

873874
#[stable(feature = "manually_drop", since = "1.20.0")]
874-
impl<T> ::ops::Deref for ManuallyDrop<T> {
875+
impl<T> Deref for ManuallyDrop<T> {
875876
type Target = T;
876877
#[inline]
877878
fn deref(&self) -> &Self::Target {
@@ -882,7 +883,7 @@ impl<T> ::ops::Deref for ManuallyDrop<T> {
882883
}
883884

884885
#[stable(feature = "manually_drop", since = "1.20.0")]
885-
impl<T> ::ops::DerefMut for ManuallyDrop<T> {
886+
impl<T> DerefMut for ManuallyDrop<T> {
886887
#[inline]
887888
fn deref_mut(&mut self) -> &mut Self::Target {
888889
unsafe {
@@ -903,16 +904,72 @@ impl<T: ::fmt::Debug> ::fmt::Debug for ManuallyDrop<T> {
903904
#[stable(feature = "manually_drop", since = "1.20.0")]
904905
impl<T: Clone> Clone for ManuallyDrop<T> {
905906
fn clone(&self) -> Self {
906-
use ::ops::Deref;
907907
ManuallyDrop::new(self.deref().clone())
908908
}
909909

910910
fn clone_from(&mut self, source: &Self) {
911-
use ::ops::DerefMut;
912911
self.deref_mut().clone_from(source);
913912
}
914913
}
915914

915+
#[stable(feature = "manually_drop", since = "1.20.0")]
916+
impl<T: Default> Default for ManuallyDrop<T> {
917+
fn default() -> Self {
918+
ManuallyDrop::new(Default::default())
919+
}
920+
}
921+
922+
#[stable(feature = "manually_drop", since = "1.20.0")]
923+
impl<T: PartialEq> PartialEq for ManuallyDrop<T> {
924+
fn eq(&self, other: &Self) -> bool {
925+
self.deref().eq(other)
926+
}
927+
928+
fn ne(&self, other: &Self) -> bool {
929+
self.deref().ne(other)
930+
}
931+
}
932+
933+
#[stable(feature = "manually_drop", since = "1.20.0")]
934+
impl<T: Eq> Eq for ManuallyDrop<T> {}
935+
936+
#[stable(feature = "manually_drop", since = "1.20.0")]
937+
impl<T: PartialOrd> PartialOrd for ManuallyDrop<T> {
938+
fn partial_cmp(&self, other: &Self) -> Option<::cmp::Ordering> {
939+
self.deref().partial_cmp(other)
940+
}
941+
942+
fn lt(&self, other: &Self) -> bool {
943+
self.deref().lt(other)
944+
}
945+
946+
fn le(&self, other: &Self) -> bool {
947+
self.deref().le(other)
948+
}
949+
950+
fn gt(&self, other: &Self) -> bool {
951+
self.deref().gt(other)
952+
}
953+
954+
fn ge(&self, other: &Self) -> bool {
955+
self.deref().ge(other)
956+
}
957+
}
958+
959+
#[stable(feature = "manually_drop", since = "1.20.0")]
960+
impl<T: Ord> Ord for ManuallyDrop<T> {
961+
fn cmp(&self, other: &Self) -> ::cmp::Ordering {
962+
self.deref().cmp(other)
963+
}
964+
}
965+
966+
#[stable(feature = "manually_drop", since = "1.20.0")]
967+
impl<T: ::hash::Hash> ::hash::Hash for ManuallyDrop<T> {
968+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
969+
self.deref().hash(state);
970+
}
971+
}
972+
916973
/// Tells LLVM that this point in the code is not reachable, enabling further
917974
/// optimizations.
918975
///

0 commit comments

Comments
 (0)