Skip to content

Commit cd06038

Browse files
committed
HirIdification: replace NodeId method calls
1 parent 88f755f commit cd06038

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+336
-339
lines changed

src/librustc/hir/map/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,10 @@ impl<'hir> Map<'hir> {
501501
}
502502

503503
/// Given a body owner's id, returns the `BodyId` associated with it.
504-
pub fn body_owned_by(&self, id: NodeId) -> BodyId {
505-
self.maybe_body_owned_by(id).unwrap_or_else(|| {
506-
span_bug!(self.span(id), "body_owned_by: {} has no associated body",
507-
self.node_to_string(id));
504+
pub fn body_owned_by(&self, id: HirId) -> BodyId {
505+
self.maybe_body_owned_by_by_hir_id(id).unwrap_or_else(|| {
506+
span_bug!(self.span_by_hir_id(id), "body_owned_by: {} has no associated body",
507+
self.hir_to_string(id));
508508
})
509509
}
510510

@@ -539,19 +539,19 @@ impl<'hir> Map<'hir> {
539539
self.body_owner_kind(node_id)
540540
}
541541

542-
pub fn ty_param_owner(&self, id: NodeId) -> NodeId {
543-
match self.get(id) {
542+
pub fn ty_param_owner(&self, id: HirId) -> HirId {
543+
match self.get_by_hir_id(id) {
544544
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => id,
545-
Node::GenericParam(_) => self.get_parent_node(id),
546-
_ => bug!("ty_param_owner: {} not a type parameter", self.node_to_string(id))
545+
Node::GenericParam(_) => self.get_parent_node_by_hir_id(id),
546+
_ => bug!("ty_param_owner: {} not a type parameter", self.hir_to_string(id))
547547
}
548548
}
549549

550-
pub fn ty_param_name(&self, id: NodeId) -> Name {
551-
match self.get(id) {
550+
pub fn ty_param_name(&self, id: HirId) -> Name {
551+
match self.get_by_hir_id(id) {
552552
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => keywords::SelfUpper.name(),
553553
Node::GenericParam(param) => param.name.ident().name,
554-
_ => bug!("ty_param_name: {} not a type parameter", self.node_to_string(id)),
554+
_ => bug!("ty_param_name: {} not a type parameter", self.hir_to_string(id)),
555555
}
556556
}
557557

src/librustc/infer/opaque_types/mod.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::hir::Node;
44
use crate::infer::{self, InferCtxt, InferOk, TypeVariableOrigin};
55
use crate::infer::outlives::free_region_map::FreeRegionRelations;
66
use rustc_data_structures::fx::FxHashMap;
7-
use syntax::ast;
87
use crate::traits::{self, PredicateObligation};
98
use crate::ty::{self, Ty, TyCtxt, GenericParamDefKind};
109
use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder};
@@ -686,13 +685,14 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
686685
// let x = || foo(); // returns the Opaque assoc with `foo`
687686
// }
688687
// ```
689-
if let Some(opaque_node_id) = tcx.hir().as_local_node_id(def_id) {
688+
if let Some(opaque_hir_id) = tcx.hir().as_local_hir_id(def_id) {
690689
let parent_def_id = self.parent_def_id;
691690
let def_scope_default = || {
692-
let opaque_parent_node_id = tcx.hir().get_parent(opaque_node_id);
693-
parent_def_id == tcx.hir().local_def_id(opaque_parent_node_id)
691+
let opaque_parent_hir_id = tcx.hir().get_parent_item(opaque_hir_id);
692+
parent_def_id == tcx.hir()
693+
.local_def_id_from_hir_id(opaque_parent_hir_id)
694694
};
695-
let in_definition_scope = match tcx.hir().find(opaque_node_id) {
695+
let in_definition_scope = match tcx.hir().find_by_hir_id(opaque_hir_id) {
696696
Some(Node::Item(item)) => match item.node {
697697
// impl trait
698698
hir::ItemKind::Existential(hir::ExistTy {
@@ -706,21 +706,21 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
706706
}) => may_define_existential_type(
707707
tcx,
708708
self.parent_def_id,
709-
opaque_node_id,
709+
opaque_hir_id,
710710
),
711711
_ => def_scope_default(),
712712
},
713713
Some(Node::ImplItem(item)) => match item.node {
714714
hir::ImplItemKind::Existential(_) => may_define_existential_type(
715715
tcx,
716716
self.parent_def_id,
717-
opaque_node_id,
717+
opaque_hir_id,
718718
),
719719
_ => def_scope_default(),
720720
},
721721
_ => bug!(
722722
"expected (impl) item, found {}",
723-
tcx.hir().node_to_string(opaque_node_id),
723+
tcx.hir().hir_to_string(opaque_hir_id),
724724
),
725725
};
726726
if in_definition_scope {
@@ -839,20 +839,20 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
839839
pub fn may_define_existential_type(
840840
tcx: TyCtxt<'_, '_, '_>,
841841
def_id: DefId,
842-
opaque_node_id: ast::NodeId,
842+
opaque_hir_id: hir::HirId,
843843
) -> bool {
844-
let mut node_id = tcx
844+
let mut hir_id = tcx
845845
.hir()
846-
.as_local_node_id(def_id)
846+
.as_local_hir_id(def_id)
847847
.unwrap();
848848
// named existential types can be defined by any siblings or
849849
// children of siblings
850-
let mod_id = tcx.hir().get_parent(opaque_node_id);
850+
let mod_id = tcx.hir().get_parent_item(opaque_hir_id);
851851
// so we walk up the node tree until we hit the root or the parent
852852
// of the opaque type
853-
while node_id != mod_id && node_id != ast::CRATE_NODE_ID {
854-
node_id = tcx.hir().get_parent(node_id);
853+
while hir_id != mod_id && hir_id != hir::CRATE_HIR_ID {
854+
hir_id = tcx.hir().get_parent_item(hir_id);
855855
}
856856
// syntactically we are allowed to define the concrete type
857-
node_id == mod_id
857+
hir_id == mod_id
858858
}

src/librustc/middle/expr_use_visitor.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -918,9 +918,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
918918
fn walk_captures(&mut self, closure_expr: &hir::Expr, fn_decl_span: Span) {
919919
debug!("walk_captures({:?})", closure_expr);
920920

921-
let closure_node_id = self.tcx().hir().hir_to_node_id(closure_expr.hir_id);
922-
let closure_def_id = self.tcx().hir().local_def_id(closure_node_id);
923-
self.tcx().with_freevars(closure_node_id, |freevars| {
921+
let closure_def_id = self.tcx().hir().local_def_id_from_hir_id(closure_expr.hir_id);
922+
self.tcx().with_freevars(closure_expr.hir_id, |freevars| {
924923
for freevar in freevars {
925924
let var_hir_id = self.tcx().hir().node_to_hir_id(freevar.var_id());
926925
let upvar_id = ty::UpvarId {

src/librustc/middle/liveness.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,7 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) {
476476
// in better error messages than just pointing at the closure
477477
// construction site.
478478
let mut call_caps = Vec::new();
479-
let node_id = ir.tcx.hir().hir_to_node_id(expr.hir_id);
480-
ir.tcx.with_freevars(node_id, |freevars| {
479+
ir.tcx.with_freevars(expr.hir_id, |freevars| {
481480
call_caps.extend(freevars.iter().filter_map(|fv| {
482481
if let Def::Local(rv) = fv.def {
483482
let fv_ln = ir.add_live_node(FreeVarNode(fv.span));

src/librustc/middle/reachable.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ fn method_might_be_inlined<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
5151
if codegen_fn_attrs.requests_inline() || generics.requires_monomorphization(tcx) {
5252
return true
5353
}
54-
if let Some(impl_node_id) = tcx.hir().as_local_node_id(impl_src) {
55-
match tcx.hir().find(impl_node_id) {
54+
if let Some(impl_hir_id) = tcx.hir().as_local_hir_id(impl_src) {
55+
match tcx.hir().find_by_hir_id(impl_hir_id) {
5656
Some(Node::Item(item)) =>
5757
item_might_be_inlined(tcx, &item, codegen_fn_attrs),
5858
Some(..) | None =>
@@ -141,12 +141,12 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
141141
// Returns true if the given def ID represents a local item that is
142142
// eligible for inlining and false otherwise.
143143
fn def_id_represents_local_inlined_item(&self, def_id: DefId) -> bool {
144-
let node_id = match self.tcx.hir().as_local_node_id(def_id) {
145-
Some(node_id) => node_id,
144+
let hir_id = match self.tcx.hir().as_local_hir_id(def_id) {
145+
Some(hir_id) => hir_id,
146146
None => { return false; }
147147
};
148148

149-
match self.tcx.hir().find(node_id) {
149+
match self.tcx.hir().find_by_hir_id(hir_id) {
150150
Some(Node::Item(item)) => {
151151
match item.node {
152152
hir::ItemKind::Fn(..) =>
@@ -173,7 +173,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
173173
} else {
174174
let impl_did = self.tcx
175175
.hir()
176-
.get_parent_did(node_id);
176+
.get_parent_did_by_hir_id(hir_id);
177177
// Check the impl. If the generics on the self
178178
// type of the impl require inlining, this method
179179
// does too.

src/librustc/middle/region.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ pub struct ScopeTree {
223223
/// The parent of the root body owner, if the latter is an
224224
/// an associated const or method, as impls/traits can also
225225
/// have lifetime parameters free in this body.
226-
root_parent: Option<ast::NodeId>,
226+
root_parent: Option<hir::HirId>,
227227

228228
/// `parent_map` maps from a scope ID to the enclosing scope id;
229229
/// this is usually corresponding to the lexical nesting, though
@@ -650,8 +650,8 @@ impl<'tcx> ScopeTree {
650650
-> Scope {
651651
let param_owner = tcx.parent_def_id(br.def_id).unwrap();
652652

653-
let param_owner_id = tcx.hir().as_local_node_id(param_owner).unwrap();
654-
let scope = tcx.hir().maybe_body_owned_by(param_owner_id).map(|body_id| {
653+
let param_owner_id = tcx.hir().as_local_hir_id(param_owner).unwrap();
654+
let scope = tcx.hir().maybe_body_owned_by_by_hir_id(param_owner_id).map(|body_id| {
655655
tcx.hir().body(body_id).value.hir_id.local_id
656656
}).unwrap_or_else(|| {
657657
// The lifetime was defined on node that doesn't own a body,
@@ -661,7 +661,7 @@ impl<'tcx> ScopeTree {
661661
"free_scope: {:?} not recognized by the \
662662
region scope tree for {:?} / {:?}",
663663
param_owner,
664-
self.root_parent.map(|id| tcx.hir().local_def_id(id)),
664+
self.root_parent.map(|id| tcx.hir().local_def_id_from_hir_id(id)),
665665
self.root_body.map(|hir_id| DefId::local(hir_id.owner)));
666666

667667
// The trait/impl lifetime is in scope for the method's body.
@@ -686,7 +686,7 @@ impl<'tcx> ScopeTree {
686686
// on the same function that they ended up being freed in.
687687
assert_eq!(param_owner, fr.scope);
688688

689-
let param_owner_id = tcx.hir().as_local_node_id(param_owner).unwrap();
689+
let param_owner_id = tcx.hir().as_local_hir_id(param_owner).unwrap();
690690
let body_id = tcx.hir().body_owned_by(param_owner_id);
691691
Scope { id: tcx.hir().body(body_id).value.hir_id.local_id, data: ScopeData::CallSite }
692692
}
@@ -1328,8 +1328,8 @@ fn region_scope_tree<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
13281328
return tcx.region_scope_tree(closure_base_def_id);
13291329
}
13301330

1331-
let id = tcx.hir().as_local_node_id(def_id).unwrap();
1332-
let scope_tree = if let Some(body_id) = tcx.hir().maybe_body_owned_by(id) {
1331+
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
1332+
let scope_tree = if let Some(body_id) = tcx.hir().maybe_body_owned_by_by_hir_id(id) {
13331333
let mut visitor = RegionResolutionVisitor {
13341334
tcx,
13351335
scope_tree: ScopeTree::default(),
@@ -1348,10 +1348,10 @@ fn region_scope_tree<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
13481348
// If the item is an associated const or a method,
13491349
// record its impl/trait parent, as it can also have
13501350
// lifetime parameters free in this body.
1351-
match tcx.hir().get(id) {
1351+
match tcx.hir().get_by_hir_id(id) {
13521352
Node::ImplItem(_) |
13531353
Node::TraitItem(_) => {
1354-
visitor.scope_tree.root_parent = Some(tcx.hir().get_parent(id));
1354+
visitor.scope_tree.root_parent = Some(tcx.hir().get_parent_item(id));
13551355
}
13561356
_ => {}
13571357
}

src/librustc/middle/resolve_lifetime.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1585,9 +1585,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15851585

15861586
match lifetimeuseset {
15871587
Some(LifetimeUseSet::One(lifetime)) => {
1588-
let node_id = self.tcx.hir().as_local_node_id(def_id).unwrap();
1589-
debug!("node id first={:?}", node_id);
1590-
if let Some((id, span, name)) = match self.tcx.hir().get(node_id) {
1588+
let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap();
1589+
debug!("hir id first={:?}", hir_id);
1590+
if let Some((id, span, name)) = match self.tcx.hir().get_by_hir_id(hir_id) {
15911591
Node::Lifetime(hir_lifetime) => Some((
15921592
hir_lifetime.hir_id,
15931593
hir_lifetime.span,
@@ -1626,8 +1626,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
16261626
debug!("Not one use lifetime");
16271627
}
16281628
None => {
1629-
let node_id = self.tcx.hir().as_local_node_id(def_id).unwrap();
1630-
if let Some((id, span, name)) = match self.tcx.hir().get(node_id) {
1629+
let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap();
1630+
if let Some((id, span, name)) = match self.tcx.hir().get_by_hir_id(hir_id) {
16311631
Node::Lifetime(hir_lifetime) => Some((
16321632
hir_lifetime.hir_id,
16331633
hir_lifetime.span,

src/librustc/mir/mod.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -2411,15 +2411,15 @@ impl<'tcx> Debug for Rvalue<'tcx> {
24112411
}
24122412

24132413
AggregateKind::Closure(def_id, _) => ty::tls::with(|tcx| {
2414-
if let Some(node_id) = tcx.hir().as_local_node_id(def_id) {
2414+
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
24152415
let name = if tcx.sess.opts.debugging_opts.span_free_formats {
2416-
format!("[closure@{:?}]", node_id)
2416+
format!("[closure@{:?}]", hir_id)
24172417
} else {
2418-
format!("[closure@{:?}]", tcx.hir().span(node_id))
2418+
format!("[closure@{:?}]", tcx.hir().span_by_hir_id(hir_id))
24192419
};
24202420
let mut struct_fmt = fmt.debug_struct(&name);
24212421

2422-
tcx.with_freevars(node_id, |freevars| {
2422+
tcx.with_freevars(hir_id, |freevars| {
24232423
for (freevar, place) in freevars.iter().zip(places) {
24242424
let var_name = tcx.hir().name(freevar.var_id());
24252425
struct_fmt.field(&var_name.as_str(), place);
@@ -2433,11 +2433,12 @@ impl<'tcx> Debug for Rvalue<'tcx> {
24332433
}),
24342434

24352435
AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| {
2436-
if let Some(node_id) = tcx.hir().as_local_node_id(def_id) {
2437-
let name = format!("[generator@{:?}]", tcx.hir().span(node_id));
2436+
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
2437+
let name = format!("[generator@{:?}]",
2438+
tcx.hir().span_by_hir_id(hir_id));
24382439
let mut struct_fmt = fmt.debug_struct(&name);
24392440

2440-
tcx.with_freevars(node_id, |freevars| {
2441+
tcx.with_freevars(hir_id, |freevars| {
24412442
for (freevar, place) in freevars.iter().zip(places) {
24422443
let var_name = tcx.hir().name(freevar.var_id());
24432444
struct_fmt.field(&var_name.as_str(), place);

src/librustc/mir/mono.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
2-
use syntax::ast::NodeId;
2+
use crate::hir::HirId;
33
use syntax::symbol::{Symbol, InternedString};
44
use crate::ty::{Instance, TyCtxt};
55
use crate::util::nodemap::FxHashMap;
@@ -14,7 +14,7 @@ use std::hash::Hash;
1414
pub enum MonoItem<'tcx> {
1515
Fn(Instance<'tcx>),
1616
Static(DefId),
17-
GlobalAsm(NodeId),
17+
GlobalAsm(HirId),
1818
}
1919

2020
impl<'tcx> MonoItem<'tcx> {

src/librustc/traits/error_reporting.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
761761
let found_kind = self.closure_kind(closure_def_id, closure_substs).unwrap();
762762
let closure_span = self.tcx.sess.source_map()
763763
.def_span(self.tcx.hir().span_if_local(closure_def_id).unwrap());
764-
let node_id = self.tcx.hir().as_local_node_id(closure_def_id).unwrap();
764+
let hir_id = self.tcx.hir().as_local_hir_id(closure_def_id).unwrap();
765765
let mut err = struct_span_err!(
766766
self.tcx.sess, closure_span, E0525,
767767
"expected a closure that implements the `{}` trait, \
@@ -780,8 +780,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
780780
// a particular trait.
781781
if let Some(tables) = self.in_progress_tables {
782782
let tables = tables.borrow();
783-
let closure_hir_id = self.tcx.hir().node_to_hir_id(node_id);
784-
match (found_kind, tables.closure_kind_origins().get(closure_hir_id)) {
783+
match (found_kind, tables.closure_kind_origins().get(hir_id)) {
785784
(ty::ClosureKind::FnOnce, Some((span, name))) => {
786785
err.span_label(*span, format!(
787786
"closure is `FnOnce` because it moves the \

src/librustc/ty/constness.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
6767
pub fn provide<'tcx>(providers: &mut Providers<'tcx>) {
6868
/// only checks whether the function has a `const` modifier
6969
fn is_const_fn_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
70-
let node_id = tcx.hir().as_local_node_id(def_id)
71-
.expect("Non-local call to local provider is_const_fn");
70+
let hir_id = tcx.hir().as_local_hir_id(def_id)
71+
.expect("Non-local call to local provider is_const_fn");
7272

73-
if let Some(fn_like) = FnLikeNode::from_node(tcx.hir().get(node_id)) {
73+
if let Some(fn_like) = FnLikeNode::from_node(tcx.hir().get_by_hir_id(hir_id)) {
7474
fn_like.constness() == hir::Constness::Const
7575
} else {
7676
false

0 commit comments

Comments
 (0)