Skip to content

Commit aa53741

Browse files
committed
HirIdification: remove all NodeIds from typeck
1 parent 401329e commit aa53741

File tree

4 files changed

+16
-23
lines changed

4 files changed

+16
-23
lines changed

src/librustc_typeck/check/method/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
196196
)?;
197197

198198
if let Some(import_id) = pick.import_id {
199-
let import_def_id = self.tcx.hir().local_def_id(import_id);
199+
let import_def_id = self.tcx.hir().local_def_id_from_hir_id(import_id);
200200
debug!("used_trait_import: {:?}", import_def_id);
201201
Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports)
202202
.unwrap().insert(import_def_id);
@@ -428,7 +428,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
428428
self_ty, expr_id, ProbeScope::TraitsInScope)?;
429429
debug!("resolve_ufcs: pick={:?}", pick);
430430
if let Some(import_id) = pick.import_id {
431-
let import_def_id = tcx.hir().local_def_id(import_id);
431+
let import_def_id = tcx.hir().local_def_id_from_hir_id(import_id);
432432
debug!("resolve_ufcs: used_trait_import: {:?}", import_def_id);
433433
Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports)
434434
.unwrap().insert(import_def_id);

src/librustc_typeck/check/method/probe.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct Candidate<'tcx> {
120120
xform_ret_ty: Option<Ty<'tcx>>,
121121
item: ty::AssociatedItem,
122122
kind: CandidateKind<'tcx>,
123-
import_id: Option<ast::NodeId>,
123+
import_id: Option<hir::HirId>,
124124
}
125125

126126
#[derive(Debug)]
@@ -145,7 +145,7 @@ enum ProbeResult {
145145
pub struct Pick<'tcx> {
146146
pub item: ty::AssociatedItem,
147147
pub kind: PickKind<'tcx>,
148-
pub import_id: Option<ast::NodeId>,
148+
pub import_id: Option<hir::HirId>,
149149

150150
// Indicates that the source expression should be autoderef'd N times
151151
//
@@ -836,7 +836,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
836836
for trait_candidate in applicable_traits.iter() {
837837
let trait_did = trait_candidate.def_id;
838838
if duplicates.insert(trait_did) {
839-
let import_id = trait_candidate.import_id;
839+
let import_id = trait_candidate.import_id.map(|node_id|
840+
self.fcx.tcx.hir().node_to_hir_id(node_id));
840841
let result = self.assemble_extension_candidates_for_trait(import_id, trait_did);
841842
result?;
842843
}
@@ -887,7 +888,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
887888
}
888889

889890
fn assemble_extension_candidates_for_trait(&mut self,
890-
import_id: Option<ast::NodeId>,
891+
import_id: Option<hir::HirId>,
891892
trait_def_id: DefId)
892893
-> Result<(), MethodError<'tcx>> {
893894
debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})",

src/librustc_typeck/check/mod.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -4966,10 +4966,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
49664966
// that highlight errors inline.
49674967
let mut sp = blk.span;
49684968
let mut fn_span = None;
4969-
let blk_node_id = self.tcx.hir().hir_to_node_id(blk.hir_id);
4970-
if let Some((decl, ident)) = self.get_parent_fn_decl(blk_node_id) {
4969+
if let Some((decl, ident)) = self.get_parent_fn_decl(blk.hir_id) {
49714970
let ret_sp = decl.output.span();
4972-
if let Some(block_sp) = self.parent_item_span(blk_node_id) {
4971+
if let Some(block_sp) = self.parent_item_span(blk.hir_id) {
49734972
// HACK: on some cases (`ui/liveness/liveness-issue-2163.rs`) the
49744973
// output would otherwise be incorrect and even misleading. Make sure
49754974
// the span we're aiming at correspond to a `fn` body.
@@ -5009,8 +5008,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
50095008
ty
50105009
}
50115010

5012-
fn parent_item_span(&self, id: ast::NodeId) -> Option<Span> {
5013-
let node = self.tcx.hir().get(self.tcx.hir().get_parent(id));
5011+
fn parent_item_span(&self, id: hir::HirId) -> Option<Span> {
5012+
let node = self.tcx.hir().get_by_hir_id(self.tcx.hir().get_parent_item(id));
50145013
match node {
50155014
Node::Item(&hir::Item {
50165015
node: hir::ItemKind::Fn(_, _, _, body_id), ..
@@ -5028,9 +5027,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
50285027
None
50295028
}
50305029

5031-
/// Given a function block's `NodeId`, returns its `FnDecl` if it exists, or `None` otherwise.
5032-
fn get_parent_fn_decl(&self, blk_id: ast::NodeId) -> Option<(hir::FnDecl, ast::Ident)> {
5033-
let parent = self.tcx.hir().get(self.tcx.hir().get_parent(blk_id));
5030+
/// Given a function block's `HirId`, returns its `FnDecl` if it exists, or `None` otherwise.
5031+
fn get_parent_fn_decl(&self, blk_id: hir::HirId) -> Option<(hir::FnDecl, ast::Ident)> {
5032+
let parent = self.tcx.hir().get_by_hir_id(self.tcx.hir().get_parent_item(blk_id));
50345033
self.get_node_fn_decl(parent).map(|(fn_decl, ident, _)| (fn_decl, ident))
50355034
}
50365035

src/librustc_typeck/check/writeback.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc::ty::{self, Ty, TyCtxt};
1515
use rustc::util::nodemap::DefIdSet;
1616
use rustc_data_structures::sync::Lrc;
1717
use std::mem;
18-
use syntax::ast;
1918
use syntax_pos::Span;
2019

2120
///////////////////////////////////////////////////////////////////////////
@@ -444,8 +443,8 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
444443

445444
fn visit_opaque_types(&mut self, span: Span) {
446445
for (&def_id, opaque_defn) in self.fcx.opaque_types.borrow().iter() {
447-
let node_id = self.tcx().hir().as_local_node_id(def_id).unwrap();
448-
let instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &node_id);
446+
let hir_id = self.tcx().hir().as_local_hir_id(def_id).unwrap();
447+
let instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &hir_id);
449448

450449
let generics = self.tcx().generics_of(def_id);
451450

@@ -731,12 +730,6 @@ impl Locatable for Span {
731730
}
732731
}
733732

734-
impl Locatable for ast::NodeId {
735-
fn to_span(&self, tcx: &TyCtxt<'_, '_, '_>) -> Span {
736-
tcx.hir().span(*self)
737-
}
738-
}
739-
740733
impl Locatable for DefIndex {
741734
fn to_span(&self, tcx: &TyCtxt<'_, '_, '_>) -> Span {
742735
let hir_id = tcx.hir().def_index_to_hir_id(*self);

0 commit comments

Comments
 (0)