1
+ use crate :: HashStableContext ;
2
+ use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
1
3
use rustc_data_structures:: AtomicRef ;
2
4
use rustc_index:: vec:: Idx ;
3
5
use rustc_serialize:: { Decoder , Encoder } ;
@@ -18,15 +20,6 @@ pub enum CrateNum {
18
20
Index ( CrateId ) ,
19
21
}
20
22
21
- impl :: std:: fmt:: Debug for CrateNum {
22
- fn fmt ( & self , fmt : & mut :: std:: fmt:: Formatter < ' _ > ) -> :: std:: fmt:: Result {
23
- match self {
24
- CrateNum :: Index ( id) => write ! ( fmt, "crate{}" , id. private) ,
25
- CrateNum :: ReservedForIncrCompCache => write ! ( fmt, "crate for decoding incr comp cache" ) ,
26
- }
27
- }
28
- }
29
-
30
23
/// Item definitions in the currently-compiled crate would have the `CrateNum`
31
24
/// `LOCAL_CRATE` in their `DefId`.
32
25
pub const LOCAL_CRATE : CrateNum = CrateNum :: Index ( CrateId :: from_u32_const ( 0 ) ) ;
@@ -100,6 +93,15 @@ impl rustc_serialize::UseSpecializedDecodable for CrateNum {
100
93
}
101
94
}
102
95
96
+ impl :: std:: fmt:: Debug for CrateNum {
97
+ fn fmt ( & self , fmt : & mut :: std:: fmt:: Formatter < ' _ > ) -> :: std:: fmt:: Result {
98
+ match self {
99
+ CrateNum :: Index ( id) => write ! ( fmt, "crate{}" , id. private) ,
100
+ CrateNum :: ReservedForIncrCompCache => write ! ( fmt, "crate for decoding incr comp cache" ) ,
101
+ }
102
+ }
103
+ }
104
+
103
105
rustc_index:: newtype_index! {
104
106
/// A DefIndex is an index into the hir-map for a crate, identifying a
105
107
/// particular definition. It should really be considered an interned
@@ -207,3 +209,9 @@ impl fmt::Debug for LocalDefId {
207
209
208
210
impl rustc_serialize:: UseSpecializedEncodable for LocalDefId { }
209
211
impl rustc_serialize:: UseSpecializedDecodable for LocalDefId { }
212
+
213
+ impl < CTX : HashStableContext > HashStable < CTX > for DefId {
214
+ fn hash_stable ( & self , hcx : & mut CTX , hasher : & mut StableHasher ) {
215
+ hcx. hash_def_id ( * self , hasher)
216
+ }
217
+ }
0 commit comments