Skip to content

Commit 2b0a21e

Browse files
committed
rustc: use LocalDefId instead of DefIndex in ich.
1 parent f3ec069 commit 2b0a21e

File tree

3 files changed

+12
-27
lines changed

3 files changed

+12
-27
lines changed

src/librustc/ich/hcx.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
88
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
99
use rustc_data_structures::sync::Lrc;
1010
use rustc_hir as hir;
11-
use rustc_hir::def_id::{DefId, DefIndex};
11+
use rustc_hir::def_id::{DefId, LocalDefId};
1212
use rustc_session::Session;
1313
use rustc_span::source_map::SourceMap;
1414
use rustc_span::symbol::Symbol;
@@ -124,15 +124,15 @@ impl<'a> StableHashingContext<'a> {
124124
#[inline]
125125
pub fn def_path_hash(&self, def_id: DefId) -> DefPathHash {
126126
if let Some(def_id) = def_id.as_local() {
127-
self.definitions.def_path_hash(def_id.local_def_index)
127+
self.local_def_path_hash(def_id)
128128
} else {
129129
self.cstore.def_path_hash(def_id)
130130
}
131131
}
132132

133133
#[inline]
134-
pub fn local_def_path_hash(&self, def_index: DefIndex) -> DefPathHash {
135-
self.definitions.def_path_hash(def_index)
134+
pub fn local_def_path_hash(&self, def_id: LocalDefId) -> DefPathHash {
135+
self.definitions.def_path_hash(def_id.local_def_index)
136136
}
137137

138138
#[inline]

src/librustc/ich/impls_hir.rs

+5-20
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::ich::{Fingerprint, NodeIdHashingMode, StableHashingContext};
66
use rustc_attr as attr;
77
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
88
use rustc_hir as hir;
9-
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
9+
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX};
1010
use smallvec::SmallVec;
1111
use std::mem;
1212

@@ -21,7 +21,7 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
2121
NodeIdHashingMode::HashDefPath => {
2222
let hir::HirId { owner, local_id } = hir_id;
2323

24-
hcx.local_def_path_hash(owner.local_def_index).hash_stable(hcx, hasher);
24+
hcx.local_def_path_hash(owner).hash_stable(hcx, hasher);
2525
local_id.hash_stable(hcx, hasher);
2626
}
2727
}
@@ -116,8 +116,8 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
116116
}
117117

118118
#[inline]
119-
fn local_def_path_hash(&self, def_index: DefIndex) -> DefPathHash {
120-
self.local_def_path_hash(def_index)
119+
fn local_def_path_hash(&self, def_id: LocalDefId) -> DefPathHash {
120+
self.local_def_path_hash(def_id)
121121
}
122122
}
123123

@@ -197,21 +197,6 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::BodyId {
197197
}
198198
}
199199

200-
impl<'a> HashStable<StableHashingContext<'a>> for hir::def_id::DefIndex {
201-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
202-
hcx.local_def_path_hash(*self).hash_stable(hcx, hasher);
203-
}
204-
}
205-
206-
impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::def_id::DefIndex {
207-
type KeyType = DefPathHash;
208-
209-
#[inline]
210-
fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> DefPathHash {
211-
hcx.local_def_path_hash(*self)
212-
}
213-
}
214-
215200
impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitCandidate {
216201
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
217202
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
@@ -231,7 +216,7 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::TraitCandidate {
231216

232217
let import_keys = import_ids
233218
.iter()
234-
.map(|hir_id| (hcx.local_def_path_hash(hir_id.owner.local_def_index), hir_id.local_id))
219+
.map(|hir_id| (hcx.local_def_path_hash(hir_id.owner), hir_id.local_id))
235220
.collect();
236221
(hcx.def_path_hash(*def_id), import_keys)
237222
}

src/librustc_hir/stable_hash_impls.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::hir::{
55
VisibilityKind,
66
};
77
use crate::hir_id::{HirId, ItemLocalId};
8-
use rustc_span::def_id::{DefIndex, DefPathHash};
8+
use rustc_span::def_id::{DefPathHash, LocalDefId};
99

1010
/// Requirements for a `StableHashingContext` to be used in this crate.
1111
/// This is a hack to allow using the `HashStable_Generic` derive macro
@@ -21,15 +21,15 @@ pub trait HashStableContext:
2121
fn hash_hir_ty(&mut self, _: &Ty<'_>, hasher: &mut StableHasher);
2222
fn hash_hir_visibility_kind(&mut self, _: &VisibilityKind<'_>, hasher: &mut StableHasher);
2323
fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self, f: F);
24-
fn local_def_path_hash(&self, def_index: DefIndex) -> DefPathHash;
24+
fn local_def_path_hash(&self, def_id: LocalDefId) -> DefPathHash;
2525
}
2626

2727
impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
2828
type KeyType = (DefPathHash, ItemLocalId);
2929

3030
#[inline]
3131
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
32-
let def_path_hash = hcx.local_def_path_hash(self.owner.local_def_index);
32+
let def_path_hash = hcx.local_def_path_hash(self.owner);
3333
(def_path_hash, self.local_id)
3434
}
3535
}

0 commit comments

Comments
 (0)