@@ -22,6 +22,7 @@ use hash;
22
22
use intrinsics;
23
23
use marker:: { Copy , PhantomData , Sized } ;
24
24
use ptr;
25
+ use ops:: { Deref , DerefMut } ;
25
26
26
27
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
27
28
pub use intrinsics:: transmute;
@@ -821,6 +822,7 @@ pub fn discriminant<T>(v: &T) -> Discriminant<T> {
821
822
/// ```
822
823
#[ stable( feature = "manually_drop" , since = "1.20.0" ) ]
823
824
#[ allow( unions_with_drop_fields) ]
825
+ #[ derive( Copy ) ]
824
826
pub union ManuallyDrop < T > { value : T }
825
827
826
828
impl < T > ManuallyDrop < T > {
@@ -870,7 +872,7 @@ impl<T> ManuallyDrop<T> {
870
872
}
871
873
872
874
#[ stable( feature = "manually_drop" , since = "1.20.0" ) ]
873
- impl < T > :: ops :: Deref for ManuallyDrop < T > {
875
+ impl < T > Deref for ManuallyDrop < T > {
874
876
type Target = T ;
875
877
#[ inline]
876
878
fn deref ( & self ) -> & Self :: Target {
@@ -881,7 +883,7 @@ impl<T> ::ops::Deref for ManuallyDrop<T> {
881
883
}
882
884
883
885
#[ stable( feature = "manually_drop" , since = "1.20.0" ) ]
884
- impl < T > :: ops :: DerefMut for ManuallyDrop < T > {
886
+ impl < T > DerefMut for ManuallyDrop < T > {
885
887
#[ inline]
886
888
fn deref_mut ( & mut self ) -> & mut Self :: Target {
887
889
unsafe {
@@ -899,6 +901,75 @@ impl<T: ::fmt::Debug> ::fmt::Debug for ManuallyDrop<T> {
899
901
}
900
902
}
901
903
904
+ #[ stable( feature = "manually_drop" , since = "1.20.0" ) ]
905
+ impl < T : Clone > Clone for ManuallyDrop < T > {
906
+ fn clone ( & self ) -> Self {
907
+ ManuallyDrop :: new ( self . deref ( ) . clone ( ) )
908
+ }
909
+
910
+ fn clone_from ( & mut self , source : & Self ) {
911
+ self . deref_mut ( ) . clone_from ( source) ;
912
+ }
913
+ }
914
+
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
+
902
973
/// Tells LLVM that this point in the code is not reachable, enabling further
903
974
/// optimizations.
904
975
///
0 commit comments