Skip to content

Commit a95a0b9

Browse files
committed
Revert "Remove HirId to NodeId conversion APIs"
This reverts commit 6a0f1af.
1 parent 3c94dd1 commit a95a0b9

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/librustc_hir/definitions.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ impl Definitions {
337337
self.local_def_id_to_hir_id(def_id)
338338
}
339339

340+
#[inline]
341+
pub fn hir_id_to_node_id(&self, hir_id: hir::HirId) -> ast::NodeId {
342+
self.hir_id_to_node_id[&hir_id]
343+
}
344+
340345
#[inline]
341346
pub fn local_def_id_to_hir_id(&self, id: LocalDefId) -> hir::HirId {
342347
let node_id = self.def_id_to_node_id[id];
@@ -351,7 +356,7 @@ impl Definitions {
351356

352357
#[inline]
353358
pub fn opt_hir_id_to_local_def_id(&self, hir_id: hir::HirId) -> Option<LocalDefId> {
354-
let node_id = self.hir_id_to_node_id[&hir_id];
359+
let node_id = self.hir_id_to_node_id(hir_id);
355360
self.opt_local_def_id(node_id)
356361
}
357362

src/librustc_middle/hir/map/collector.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,10 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
242242
// Make sure that the DepNode of some node coincides with the HirId
243243
// owner of that node.
244244
if cfg!(debug_assertions) {
245+
let node_id = self.definitions.hir_id_to_node_id(hir_id);
246+
245247
if hir_id.owner != self.current_dep_node_owner {
246-
let node_str = match self.definitions.opt_hir_id_to_local_def_id(hir_id) {
248+
let node_str = match self.definitions.opt_local_def_id(node_id) {
247249
Some(def_id) => self.definitions.def_path(def_id).to_string_no_crate(),
248250
None => format!("{:?}", node),
249251
};
@@ -333,7 +335,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
333335
debug!("visit_item: {:?}", i);
334336
debug_assert_eq!(
335337
i.hir_id.owner,
336-
self.definitions.opt_hir_id_to_local_def_id(i.hir_id).unwrap()
338+
self.definitions
339+
.opt_local_def_id(self.definitions.hir_id_to_node_id(i.hir_id))
340+
.unwrap()
337341
);
338342
self.with_dep_node_owner(i.hir_id.owner, i, |this, hash| {
339343
this.insert_with_hash(i.span, i.hir_id, Node::Item(i), hash);
@@ -365,7 +369,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
365369
fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) {
366370
debug_assert_eq!(
367371
ti.hir_id.owner,
368-
self.definitions.opt_hir_id_to_local_def_id(ti.hir_id).unwrap()
372+
self.definitions
373+
.opt_local_def_id(self.definitions.hir_id_to_node_id(ti.hir_id))
374+
.unwrap()
369375
);
370376
self.with_dep_node_owner(ti.hir_id.owner, ti, |this, hash| {
371377
this.insert_with_hash(ti.span, ti.hir_id, Node::TraitItem(ti), hash);
@@ -379,7 +385,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
379385
fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) {
380386
debug_assert_eq!(
381387
ii.hir_id.owner,
382-
self.definitions.opt_hir_id_to_local_def_id(ii.hir_id).unwrap()
388+
self.definitions
389+
.opt_local_def_id(self.definitions.hir_id_to_node_id(ii.hir_id))
390+
.unwrap()
383391
);
384392
self.with_dep_node_owner(ii.hir_id.owner, ii, |this, hash| {
385393
this.insert_with_hash(ii.span, ii.hir_id, Node::ImplItem(ii), hash);

0 commit comments

Comments
 (0)