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();
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);
})
}
// 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));
}
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 {:?}",
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)
}))
}
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)
}
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());
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)
}
}
}
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);