scrap find_node_for_hir_id in favor of hir_to_node_id

Michael Woerister pointed out that `hir_to_node_id` (introduced in
August 2017's 28ddd7a4e) supersedes the functionality of
`find_node_for_hir_id` (just a hash lookup compared to that linear
search).
This commit is contained in:
Zack M. Davis 2018-05-26 17:30:26 -07:00
parent 078486b9f6
commit 1b7488d40b
7 changed files with 8 additions and 20 deletions

View file

@ -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();

View file

@ -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);
})
}

View file

@ -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));
}

View file

@ -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 {:?}",
@ -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)
}))
}
@ -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)
}

View file

@ -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());

View file

@ -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)
}
}

View file

@ -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);