Skip to content

Commit

Permalink
scrap find_node_for_hir_id in favor of hir_to_node_id
Browse files Browse the repository at this point in the history
Michael Woerister pointed out that `hir_to_node_id` (introduced in
August 2017's 28ddd7a) supersedes the functionality of
`find_node_for_hir_id` (just a hash lookup compared to that linear
search).
  • Loading branch information
zackmdavis committed May 28, 2018
1 parent 078486b commit 1b7488d
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 20 deletions.
8 changes: 0 additions & 8 deletions src/librustc/hir/map/definitions.rs
Expand Up @@ -487,14 +487,6 @@ impl Definitions {
self.node_to_hir_id[node_id]
}

pub fn find_node_for_hir_id(&self, hir_id: hir::HirId) -> ast::NodeId {
self.node_to_hir_id
.iter()
.position(|x| *x == hir_id)
.map(|idx| ast::NodeId::new(idx))
.unwrap()
}

#[inline]
pub fn def_index_to_hir_id(&self, def_index: DefIndex) -> hir::HirId {
let space_index = def_index.address_space().index();
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/expr_use_visitor.rs
Expand Up @@ -609,8 +609,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
match local.init {
None => {
local.pat.each_binding(|_, hir_id, span, _| {
// FIXME: converting HirId → NodeId is said to be relatively expensive
let node_id = self.mc.tcx.hir.definitions().find_node_for_hir_id(hir_id);
let node_id = self.mc.tcx.hir.hir_to_node_id(hir_id);
self.delegate.decl_without_init(node_id, span);
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/mem_categorization.rs
Expand Up @@ -488,7 +488,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
// FIXME
None if self.is_tainted_by_errors() => Err(()),
None => {
let id = self.tcx.hir.definitions().find_node_for_hir_id(id);
let id = self.tcx.hir.hir_to_node_id(id);
bug!("no type for node {}: {} in mem_categorization",
id, self.tcx.hir.node_to_string(id));
}
Expand Down
9 changes: 3 additions & 6 deletions src/librustc/ty/context.rs
Expand Up @@ -266,9 +266,7 @@ fn validate_hir_id_for_typeck_tables(local_id_root: Option<DefId>,
if let Some(local_id_root) = local_id_root {
if hir_id.owner != local_id_root.index {
ty::tls::with(|tcx| {
let node_id = tcx.hir
.definitions()
.find_node_for_hir_id(hir_id);
let node_id = tcx.hir.hir_to_node_id(hir_id);

bug!("node {} with HirId::owner {:?} cannot be placed in \
TypeckTables with local_id_root {:?}",
Expand Down Expand Up @@ -527,7 +525,7 @@ impl<'tcx> TypeckTables<'tcx> {
None => {
bug!("node_id_to_type: no type for node `{}`",
tls::with(|tcx| {
let id = tcx.hir.definitions().find_node_for_hir_id(id);
let id = tcx.hir.hir_to_node_id(id);
tcx.hir.node_to_string(id)
}))
}
Expand Down Expand Up @@ -2616,8 +2614,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
msg: &str)
-> DiagnosticBuilder<'tcx>
{
// FIXME: converting HirId → NodeId is said to be relatively expensive
let node_id = self.hir.definitions().find_node_for_hir_id(hir_id);
let node_id = self.hir.hir_to_node_id(hir_id);
let (level, src) = self.lint_level_at_node(lint, node_id);
lint::struct_lint_level(self.sess, lint, level, src, Some(span.into()), msg)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Expand Up @@ -2110,7 +2110,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
Some(&t) => t,
None if self.is_tainted_by_errors() => self.tcx.types.err,
None => {
let node_id = self.tcx.hir.definitions().find_node_for_hir_id(id);
let node_id = self.tcx.hir.hir_to_node_id(id);
bug!("no type for node {}: {} in fcx {}",
node_id, self.tcx.hir.node_to_string(node_id),
self.tag());
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/writeback.rs
Expand Up @@ -560,7 +560,7 @@ impl Locatable for DefIndex {

impl Locatable for hir::HirId {
fn to_span(&self, tcx: &TyCtxt) -> Span {
let node_id = tcx.hir.definitions().find_node_for_hir_id(*self);
let node_id = tcx.hir.hir_to_node_id(*self);
tcx.hir.span(node_id)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check_unused.rs
Expand Up @@ -106,7 +106,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
}
assert_eq!(def_id.krate, LOCAL_CRATE);
let hir_id = tcx.hir.definitions().def_index_to_hir_id(def_id.index);
let id = tcx.hir.definitions().find_node_for_hir_id(hir_id);
let id = tcx.hir.hir_to_node_id(hir_id);
let lint = lint::builtin::UNUSED_EXTERN_CRATES;
let msg = "unused extern crate";
tcx.lint_node(lint, id, span, msg);
Expand Down

0 comments on commit 1b7488d

Please sign in to comment.