|
| 1 | +#![allow(internal_features)] |
| 2 | +#![feature(negative_impls)] |
| 3 | +#![feature(rustc_attrs)] |
| 4 | + |
1 | 5 | use std::fmt::{self, Debug};
|
2 | 6 |
|
3 | 7 | use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey};
|
4 | 8 | use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
5 |
| -use rustc_span::HashStableContext; |
6 |
| -use rustc_span::def_id::DefPathHash; |
7 |
| - |
8 |
| -use crate::def_id::{CRATE_DEF_ID, DefId, DefIndex, LocalDefId}; |
| 9 | +pub use rustc_span::HashStableContext; |
| 10 | +use rustc_span::def_id::{CRATE_DEF_ID, DefId, DefIndex, DefPathHash, LocalDefId}; |
9 | 11 |
|
10 | 12 | #[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)]
|
11 | 13 | pub struct OwnerId {
|
@@ -171,3 +173,22 @@ pub const CRATE_HIR_ID: HirId =
|
171 | 173 | HirId { owner: OwnerId { def_id: CRATE_DEF_ID }, local_id: ItemLocalId::ZERO };
|
172 | 174 |
|
173 | 175 | pub const CRATE_OWNER_ID: OwnerId = OwnerId { def_id: CRATE_DEF_ID };
|
| 176 | + |
| 177 | +impl<CTX: rustc_span::HashStableContext> ToStableHashKey<CTX> for HirId { |
| 178 | + type KeyType = (DefPathHash, ItemLocalId); |
| 179 | + |
| 180 | + #[inline] |
| 181 | + fn to_stable_hash_key(&self, hcx: &CTX) -> (DefPathHash, ItemLocalId) { |
| 182 | + let def_path_hash = self.owner.def_id.to_stable_hash_key(hcx); |
| 183 | + (def_path_hash, self.local_id) |
| 184 | + } |
| 185 | +} |
| 186 | + |
| 187 | +impl<CTX: HashStableContext> ToStableHashKey<CTX> for ItemLocalId { |
| 188 | + type KeyType = ItemLocalId; |
| 189 | + |
| 190 | + #[inline] |
| 191 | + fn to_stable_hash_key(&self, _: &CTX) -> ItemLocalId { |
| 192 | + *self |
| 193 | + } |
| 194 | +} |
0 commit comments