HirIdification: remove all NodeIds from typeck

This commit is contained in:
ljedrz 2019-03-10 13:08:18 +01:00
parent 401329e829
commit aa53741927
4 changed files with 16 additions and 23 deletions

View file

@ -196,7 +196,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
)?;
if let Some(import_id) = pick.import_id {
let import_def_id = self.tcx.hir().local_def_id(import_id);
let import_def_id = self.tcx.hir().local_def_id_from_hir_id(import_id);
debug!("used_trait_import: {:?}", import_def_id);
Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports)
.unwrap().insert(import_def_id);
@ -428,7 +428,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self_ty, expr_id, ProbeScope::TraitsInScope)?;
debug!("resolve_ufcs: pick={:?}", pick);
if let Some(import_id) = pick.import_id {
let import_def_id = tcx.hir().local_def_id(import_id);
let import_def_id = tcx.hir().local_def_id_from_hir_id(import_id);
debug!("resolve_ufcs: used_trait_import: {:?}", import_def_id);
Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports)
.unwrap().insert(import_def_id);

View file

@ -120,7 +120,7 @@ struct Candidate<'tcx> {
xform_ret_ty: Option<Ty<'tcx>>,
item: ty::AssociatedItem,
kind: CandidateKind<'tcx>,
import_id: Option<ast::NodeId>,
import_id: Option<hir::HirId>,
}
#[derive(Debug)]
@ -145,7 +145,7 @@ enum ProbeResult {
pub struct Pick<'tcx> {
pub item: ty::AssociatedItem,
pub kind: PickKind<'tcx>,
pub import_id: Option<ast::NodeId>,
pub import_id: Option<hir::HirId>,
// Indicates that the source expression should be autoderef'd N times
//
@ -836,7 +836,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
for trait_candidate in applicable_traits.iter() {
let trait_did = trait_candidate.def_id;
if duplicates.insert(trait_did) {
let import_id = trait_candidate.import_id;
let import_id = trait_candidate.import_id.map(|node_id|
self.fcx.tcx.hir().node_to_hir_id(node_id));
let result = self.assemble_extension_candidates_for_trait(import_id, trait_did);
result?;
}
@ -887,7 +888,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
}
fn assemble_extension_candidates_for_trait(&mut self,
import_id: Option<ast::NodeId>,
import_id: Option<hir::HirId>,
trait_def_id: DefId)
-> Result<(), MethodError<'tcx>> {
debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})",

View file

@ -4966,10 +4966,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// that highlight errors inline.
let mut sp = blk.span;
let mut fn_span = None;
let blk_node_id = self.tcx.hir().hir_to_node_id(blk.hir_id);
if let Some((decl, ident)) = self.get_parent_fn_decl(blk_node_id) {
if let Some((decl, ident)) = self.get_parent_fn_decl(blk.hir_id) {
let ret_sp = decl.output.span();
if let Some(block_sp) = self.parent_item_span(blk_node_id) {
if let Some(block_sp) = self.parent_item_span(blk.hir_id) {
// HACK: on some cases (`ui/liveness/liveness-issue-2163.rs`) the
// output would otherwise be incorrect and even misleading. Make sure
// the span we're aiming at correspond to a `fn` body.
@ -5009,8 +5008,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
ty
}
fn parent_item_span(&self, id: ast::NodeId) -> Option<Span> {
let node = self.tcx.hir().get(self.tcx.hir().get_parent(id));
fn parent_item_span(&self, id: hir::HirId) -> Option<Span> {
let node = self.tcx.hir().get_by_hir_id(self.tcx.hir().get_parent_item(id));
match node {
Node::Item(&hir::Item {
node: hir::ItemKind::Fn(_, _, _, body_id), ..
@ -5028,9 +5027,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
None
}
/// Given a function block's `NodeId`, returns its `FnDecl` if it exists, or `None` otherwise.
fn get_parent_fn_decl(&self, blk_id: ast::NodeId) -> Option<(hir::FnDecl, ast::Ident)> {
let parent = self.tcx.hir().get(self.tcx.hir().get_parent(blk_id));
/// Given a function block's `HirId`, returns its `FnDecl` if it exists, or `None` otherwise.
fn get_parent_fn_decl(&self, blk_id: hir::HirId) -> Option<(hir::FnDecl, ast::Ident)> {
let parent = self.tcx.hir().get_by_hir_id(self.tcx.hir().get_parent_item(blk_id));
self.get_node_fn_decl(parent).map(|(fn_decl, ident, _)| (fn_decl, ident))
}

View file

@ -15,7 +15,6 @@ use rustc::ty::{self, Ty, TyCtxt};
use rustc::util::nodemap::DefIdSet;
use rustc_data_structures::sync::Lrc;
use std::mem;
use syntax::ast;
use syntax_pos::Span;
///////////////////////////////////////////////////////////////////////////
@ -444,8 +443,8 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
fn visit_opaque_types(&mut self, span: Span) {
for (&def_id, opaque_defn) in self.fcx.opaque_types.borrow().iter() {
let node_id = self.tcx().hir().as_local_node_id(def_id).unwrap();
let instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &node_id);
let hir_id = self.tcx().hir().as_local_hir_id(def_id).unwrap();
let instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &hir_id);
let generics = self.tcx().generics_of(def_id);
@ -731,12 +730,6 @@ impl Locatable for Span {
}
}
impl Locatable for ast::NodeId {
fn to_span(&self, tcx: &TyCtxt<'_, '_, '_>) -> Span {
tcx.hir().span(*self)
}
}
impl Locatable for DefIndex {
fn to_span(&self, tcx: &TyCtxt<'_, '_, '_>) -> Span {
let hir_id = tcx.hir().def_index_to_hir_id(*self);