@@ -11,7 +11,6 @@ use rustc_hir::def::{CtorKind, DefKind, Res};
1111use rustc_hir:: def_id:: DefId ;
1212use rustc_index:: vec:: { Idx , IndexVec } ;
1313use rustc_query_system:: ich:: StableHashingContext ;
14- use rustc_serialize:: { self , Encodable , Encoder } ;
1514use rustc_session:: DataTypeKind ;
1615use rustc_span:: symbol:: sym;
1716use rustc_target:: abi:: VariantIdx ;
@@ -20,7 +19,7 @@ use std::cell::RefCell;
2019use std:: cmp:: Ordering ;
2120use std:: hash:: { Hash , Hasher } ;
2221use std:: ops:: Range ;
23- use std:: { ptr , str} ;
22+ use std:: str;
2423
2524use super :: {
2625 Destructor , FieldDef , GenericPredicates , ReprOptions , Ty , TyCtxt , VariantDef , VariantDiscr ,
@@ -30,7 +29,7 @@ use super::{
3029pub struct AdtSizedConstraint < ' tcx > ( pub & ' tcx [ Ty < ' tcx > ] ) ;
3130
3231bitflags ! {
33- #[ derive( HashStable ) ]
32+ #[ derive( HashStable , TyEncodable , TyDecodable ) ]
3433 pub struct AdtFlags : u32 {
3534 const NO_ADT_FLAGS = 0 ;
3635 /// Indicates whether the ADT is an enum.
@@ -88,6 +87,7 @@ bitflags! {
8887///
8988/// where `x` here represents the `DefId` of `S.x`. Then, the `DefId`
9089/// can be used with [`TyCtxt::type_of()`] to get the type of the field.
90+ #[ derive( TyEncodable , TyDecodable ) ]
9191pub struct AdtDef {
9292 /// The `DefId` of the struct, enum or union item.
9393 pub did : DefId ,
@@ -113,26 +113,23 @@ impl Ord for AdtDef {
113113 }
114114}
115115
116+ /// There should be only one AdtDef for each `did`, therefore
117+ /// it is fine to implement `PartialEq` only based on `did`.
116118impl PartialEq for AdtDef {
117- // `AdtDef`s are always interned, and this is part of `TyS` equality.
118119 #[ inline]
119120 fn eq ( & self , other : & Self ) -> bool {
120- ptr :: eq ( self , other)
121+ self . did == other. did
121122 }
122123}
123124
124125impl Eq for AdtDef { }
125126
127+ /// There should be only one AdtDef for each `did`, therefore
128+ /// it is fine to implement `Hash` only based on `did`.
126129impl Hash for AdtDef {
127130 #[ inline]
128131 fn hash < H : Hasher > ( & self , s : & mut H ) {
129- ( self as * const AdtDef ) . hash ( s)
130- }
131- }
132-
133- impl < S : Encoder > Encodable < S > for AdtDef {
134- fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
135- self . did . encode ( s)
132+ self . did . hash ( s)
136133 }
137134}
138135
@@ -161,7 +158,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for AdtDef {
161158 }
162159}
163160
164- #[ derive( Copy , Clone , Debug , Eq , PartialEq , Hash ) ]
161+ #[ derive( Copy , Clone , Debug , Eq , PartialEq , Hash , TyEncodable , TyDecodable ) ]
165162pub enum AdtKind {
166163 Struct ,
167164 Union ,
0 commit comments