@@ -11,7 +11,6 @@ use rustc_hir::def::{CtorKind, DefKind, Res};
11
11
use rustc_hir:: def_id:: DefId ;
12
12
use rustc_index:: vec:: { Idx , IndexVec } ;
13
13
use rustc_query_system:: ich:: StableHashingContext ;
14
- use rustc_serialize:: { self , Encodable , Encoder } ;
15
14
use rustc_session:: DataTypeKind ;
16
15
use rustc_span:: symbol:: sym;
17
16
use rustc_target:: abi:: VariantIdx ;
@@ -20,7 +19,7 @@ use std::cell::RefCell;
20
19
use std:: cmp:: Ordering ;
21
20
use std:: hash:: { Hash , Hasher } ;
22
21
use std:: ops:: Range ;
23
- use std:: { ptr , str} ;
22
+ use std:: str;
24
23
25
24
use super :: {
26
25
Destructor , FieldDef , GenericPredicates , ReprOptions , Ty , TyCtxt , VariantDef , VariantDiscr ,
@@ -30,7 +29,7 @@ use super::{
30
29
pub struct AdtSizedConstraint < ' tcx > ( pub & ' tcx [ Ty < ' tcx > ] ) ;
31
30
32
31
bitflags ! {
33
- #[ derive( HashStable ) ]
32
+ #[ derive( HashStable , TyEncodable , TyDecodable ) ]
34
33
pub struct AdtFlags : u32 {
35
34
const NO_ADT_FLAGS = 0 ;
36
35
/// Indicates whether the ADT is an enum.
@@ -88,6 +87,7 @@ bitflags! {
88
87
///
89
88
/// where `x` here represents the `DefId` of `S.x`. Then, the `DefId`
90
89
/// can be used with [`TyCtxt::type_of()`] to get the type of the field.
90
+ #[ derive( TyEncodable , TyDecodable ) ]
91
91
pub struct AdtDef {
92
92
/// The `DefId` of the struct, enum or union item.
93
93
pub did : DefId ,
@@ -113,26 +113,23 @@ impl Ord for AdtDef {
113
113
}
114
114
}
115
115
116
+ /// There should be only one AdtDef for each `did`, therefore
117
+ /// it is fine to implement `PartialEq` only based on `did`.
116
118
impl PartialEq for AdtDef {
117
- // `AdtDef`s are always interned, and this is part of `TyS` equality.
118
119
#[ inline]
119
120
fn eq ( & self , other : & Self ) -> bool {
120
- ptr :: eq ( self , other)
121
+ self . did == other. did
121
122
}
122
123
}
123
124
124
125
impl Eq for AdtDef { }
125
126
127
+ /// There should be only one AdtDef for each `did`, therefore
128
+ /// it is fine to implement `Hash` only based on `did`.
126
129
impl Hash for AdtDef {
127
130
#[ inline]
128
131
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)
136
133
}
137
134
}
138
135
@@ -161,7 +158,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for AdtDef {
161
158
}
162
159
}
163
160
164
- #[ derive( Copy , Clone , Debug , Eq , PartialEq , Hash ) ]
161
+ #[ derive( Copy , Clone , Debug , Eq , PartialEq , Hash , TyEncodable , TyDecodable ) ]
165
162
pub enum AdtKind {
166
163
Struct ,
167
164
Union ,
0 commit comments