Skip to content

Commit

Permalink
Revert "Remove NodeId to HirId conversion APIs"
Browse files Browse the repository at this point in the history
This reverts commit a98f35f.
  • Loading branch information
marmeladema committed Jun 22, 2020
1 parent a95a0b9 commit 879ac1d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/librustc_hir/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl Definitions {
#[inline]
pub fn local_def_id(&self, node: ast::NodeId) -> LocalDefId {
self.opt_local_def_id(node).unwrap_or_else(|| {
panic!("no entry for node id: `{:?}` / `{:?}`", node, self.node_id_to_hir_id.get(node))
panic!("no entry for node id: `{:?}` / `{:?}`", node, self.opt_node_id_to_hir_id(node))
})
}

Expand All @@ -342,6 +342,16 @@ impl Definitions {
self.hir_id_to_node_id[&hir_id]
}

#[inline]
pub fn node_id_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
self.node_id_to_hir_id[node_id].unwrap()
}

#[inline]
pub fn opt_node_id_to_hir_id(&self, node_id: ast::NodeId) -> Option<hir::HirId> {
self.node_id_to_hir_id[node_id]
}

#[inline]
pub fn local_def_id_to_hir_id(&self, id: LocalDefId) -> hir::HirId {
let node_id = self.def_id_to_node_id[id];
Expand Down
1 change: 1 addition & 0 deletions src/librustc_middle/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
// owner of that node.
if cfg!(debug_assertions) {
let node_id = self.definitions.hir_id_to_node_id(hir_id);
assert_eq!(self.definitions.node_id_to_hir_id(node_id), hir_id);

if hir_id.owner != self.current_dep_node_owner {
let node_str = match self.definitions.opt_local_def_id(node_id) {
Expand Down

0 comments on commit 879ac1d

Please sign in to comment.