Skip to content

Commit dc0ef82

Browse files
authored
Rollup merge of rust-lang#61984 - ljedrz:more_node_id_pruning, r=Zoxc
More NodeId pruning Just another round of the `HirId`ification initiative. r? @Zoxc
2 parents 9eb88f3 + 0a511cc commit dc0ef82

File tree

63 files changed

+141
-177
lines changed

Some content is hidden

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

63 files changed

+141
-177
lines changed

src/librustc/hir/map/blocks.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::hir as ast;
1515
use crate::hir::map;
1616
use crate::hir::{Expr, FnDecl, Node};
1717
use crate::hir::intravisit::FnKind;
18-
use syntax::ast::{Attribute, Ident, NodeId};
18+
use syntax::ast::{Attribute, Ident};
1919
use syntax_pos::Span;
2020

2121
/// An FnLikeNode is a Node that is like a fn, in that it has a decl
@@ -83,11 +83,11 @@ impl<'a> Code<'a> {
8383
}
8484

8585
/// Attempts to construct a Code from presumed FnLike or Expr node input.
86-
pub fn from_node(map: &map::Map<'a>, id: NodeId) -> Option<Code<'a>> {
86+
pub fn from_node(map: &map::Map<'a>, id: ast::HirId) -> Option<Code<'a>> {
8787
match map.get(id) {
8888
map::Node::Block(_) => {
8989
// Use the parent, hopefully an expression node.
90-
Code::from_node(map, map.get_parent_node(id))
90+
Code::from_node(map, map.get_parent_node_by_hir_id(id))
9191
}
9292
map::Node::Expr(expr) => Some(Code::Expr(expr)),
9393
node => FnLikeNode::from_node(node).map(Code::FnLike)

src/librustc/hir/map/definitions.rs

-5
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,6 @@ impl Definitions {
397397
self.node_to_hir_id[node_id]
398398
}
399399

400-
#[inline]
401-
pub fn def_index_to_node_id(&self, def_index: DefIndex) -> ast::NodeId {
402-
self.as_local_node_id(DefId::local(def_index)).unwrap()
403-
}
404-
405400
/// Retrieves the span of the given `DefId` if `DefId` is in the local crate, the span exists
406401
/// and it's not `DUMMY_SP`.
407402
#[inline]

src/librustc/hir/map/mod.rs

+16-35
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ impl<'hir> Map<'hir> {
291291
self.definitions.def_index_to_hir_id(def_id.to_def_id().index)
292292
}
293293

294-
fn def_kind(&self, node_id: NodeId) -> Option<DefKind> {
295-
let node = if let Some(node) = self.find(node_id) {
294+
fn def_kind(&self, hir_id: HirId) -> Option<DefKind> {
295+
let node = if let Some(node) = self.find_by_hir_id(hir_id) {
296296
node
297297
} else {
298298
return None
@@ -347,7 +347,7 @@ impl<'hir> Map<'hir> {
347347
if variant_data.ctor_hir_id().is_none() {
348348
return None;
349349
}
350-
let ctor_of = match self.find(self.get_parent_node(node_id)) {
350+
let ctor_of = match self.find_by_hir_id(self.get_parent_node_by_hir_id(hir_id)) {
351351
Some(Node::Item(..)) => def::CtorOf::Struct,
352352
Some(Node::Variant(..)) => def::CtorOf::Variant,
353353
_ => unreachable!(),
@@ -458,7 +458,7 @@ impl<'hir> Map<'hir> {
458458
}
459459

460460
pub fn body_owner_kind(&self, id: HirId) -> BodyOwnerKind {
461-
match self.get_by_hir_id(id) {
461+
match self.get(id) {
462462
Node::Item(&Item { node: ItemKind::Const(..), .. }) |
463463
Node::TraitItem(&TraitItem { node: TraitItemKind::Const(..), .. }) |
464464
Node::ImplItem(&ImplItem { node: ImplItemKind::Const(..), .. }) |
@@ -482,7 +482,7 @@ impl<'hir> Map<'hir> {
482482
}
483483

484484
pub fn ty_param_owner(&self, id: HirId) -> HirId {
485-
match self.get_by_hir_id(id) {
485+
match self.get(id) {
486486
Node::Item(&Item { node: ItemKind::Trait(..), .. }) |
487487
Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => id,
488488
Node::GenericParam(_) => self.get_parent_node_by_hir_id(id),
@@ -491,7 +491,7 @@ impl<'hir> Map<'hir> {
491491
}
492492

493493
pub fn ty_param_name(&self, id: HirId) -> Name {
494-
match self.get_by_hir_id(id) {
494+
match self.get(id) {
495495
Node::Item(&Item { node: ItemKind::Trait(..), .. }) |
496496
Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => kw::SelfUpper,
497497
Node::GenericParam(param) => param.name.ident().name,
@@ -561,20 +561,14 @@ impl<'hir> Map<'hir> {
561561
}
562562

563563
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
564-
pub fn get(&self, id: NodeId) -> Node<'hir> {
565-
let hir_id = self.node_to_hir_id(id);
566-
self.get_by_hir_id(hir_id)
567-
}
568-
569-
// FIXME(@ljedrz): replace the `NodeId` variant.
570-
pub fn get_by_hir_id(&self, id: HirId) -> Node<'hir> {
564+
pub fn get(&self, id: HirId) -> Node<'hir> {
571565
// read recorded by `find`
572566
self.find_by_hir_id(id).unwrap_or_else(||
573567
bug!("couldn't find hir id {} in the HIR map", id))
574568
}
575569

576570
pub fn get_if_local(&self, id: DefId) -> Option<Node<'hir>> {
577-
self.as_local_node_id(id).map(|id| self.get(id)) // read recorded by `get`
571+
self.as_local_hir_id(id).map(|id| self.get(id)) // read recorded by `get`
578572
}
579573

580574
pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics> {
@@ -846,7 +840,7 @@ impl<'hir> Map<'hir> {
846840
if scope == CRATE_HIR_ID {
847841
return Some(CRATE_HIR_ID);
848842
}
849-
match self.get_by_hir_id(scope) {
843+
match self.get(scope) {
850844
Node::Item(i) => {
851845
match i.node {
852846
ItemKind::Existential(ExistTy { impl_trait_fn: None, .. }) => {}
@@ -927,28 +921,15 @@ impl<'hir> Map<'hir> {
927921
}
928922
}
929923

930-
pub fn expect_expr(&self, id: NodeId) -> &'hir Expr {
931-
let hir_id = self.node_to_hir_id(id);
932-
self.expect_expr_by_hir_id(hir_id)
933-
}
934-
935-
// FIXME(@ljedrz): replace the `NodeId` variant.
936-
pub fn expect_expr_by_hir_id(&self, id: HirId) -> &'hir Expr {
924+
pub fn expect_expr(&self, id: HirId) -> &'hir Expr {
937925
match self.find_by_hir_id(id) { // read recorded by find
938926
Some(Node::Expr(expr)) => expr,
939927
_ => bug!("expected expr, found {}", self.node_to_string(id))
940928
}
941929
}
942930

943-
/// Returns the name associated with the given `NodeId`'s AST.
944-
pub fn name(&self, id: NodeId) -> Name {
945-
let hir_id = self.node_to_hir_id(id);
946-
self.name_by_hir_id(hir_id)
947-
}
948-
949-
// FIXME(@ljedrz): replace the `NodeId` variant.
950-
pub fn name_by_hir_id(&self, id: HirId) -> Name {
951-
match self.get_by_hir_id(id) {
931+
pub fn name(&self, id: HirId) -> Name {
932+
match self.get(id) {
952933
Node::Item(i) => i.ident.name,
953934
Node::ForeignItem(fi) => fi.ident.name,
954935
Node::ImplItem(ii) => ii.ident.name,
@@ -958,7 +939,7 @@ impl<'hir> Map<'hir> {
958939
Node::Lifetime(lt) => lt.name.ident().name,
959940
Node::GenericParam(param) => param.name.ident().name,
960941
Node::Binding(&Pat { node: PatKind::Binding(_, _, l, _), .. }) => l.name,
961-
Node::Ctor(..) => self.name_by_hir_id(self.get_parent_item(id)),
942+
Node::Ctor(..) => self.name(self.get_parent_item(id)),
962943
_ => bug!("no name for {}", self.node_to_string(id))
963944
}
964945
}
@@ -1080,7 +1061,7 @@ impl<'hir> Map<'hir> {
10801061
}
10811062

10821063
pub fn hir_to_pretty_string(&self, id: HirId) -> String {
1083-
print::to_string(self, |s| s.print_node(self.get_by_hir_id(id)))
1064+
print::to_string(self, |s| s.print_node(self.get(id)))
10841065
}
10851066
}
10861067

@@ -1407,8 +1388,8 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
14071388

14081389
pub fn provide(providers: &mut Providers<'_>) {
14091390
providers.def_kind = |tcx, def_id| {
1410-
if let Some(node_id) = tcx.hir().as_local_node_id(def_id) {
1411-
tcx.hir().def_kind(node_id)
1391+
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
1392+
tcx.hir().def_kind(hir_id)
14121393
} else {
14131394
bug!("calling local def_kind query provider for upstream DefId: {:?}",
14141395
def_id

src/librustc/infer/error_reporting/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
617617
}
618618
hir::MatchSource::TryDesugar => {
619619
if let Some(ty::error::ExpectedFound { expected, .. }) = exp_found {
620-
let discrim_expr = self.tcx.hir().expect_expr_by_hir_id(discrim_hir_id);
620+
let discrim_expr = self.tcx.hir().expect_expr(discrim_hir_id);
621621
let discrim_ty = if let hir::ExprKind::Call(_, args) = &discrim_expr.node {
622622
let arg_expr = args.first().expect("try desugaring call w/out arg");
623623
self.in_progress_tables.and_then(|tables| {
@@ -1335,7 +1335,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13351335
// We do this to avoid suggesting code that ends up as `T: 'a'b`,
13361336
// instead we suggest `T: 'a + 'b` in that case.
13371337
let mut has_bounds = false;
1338-
if let Node::GenericParam(ref param) = hir.get_by_hir_id(id) {
1338+
if let Node::GenericParam(ref param) = hir.get(id) {
13391339
has_bounds = !param.bounds.is_empty();
13401340
}
13411341
let sp = hir.span(id);
@@ -1583,7 +1583,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15831583
format!(" for lifetime parameter `{}` in coherence check", name)
15841584
}
15851585
infer::UpvarRegion(ref upvar_id, _) => {
1586-
let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id);
1586+
let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id);
15871587
format!(" for capture of `{}` by closure", var_name)
15881588
}
15891589
infer::NLL(..) => bug!("NLL variable found in lexical phase"),

src/librustc/infer/error_reporting/need_type_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
133133
};
134134

135135
if let Some(body_id) = body_id {
136-
let expr = self.tcx.hir().expect_expr_by_hir_id(body_id.hir_id);
136+
let expr = self.tcx.hir().expect_expr(body_id.hir_id);
137137
local_visitor.visit_expr(expr);
138138
}
139139

src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
2929
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
3030
let def_id = anon_reg.def_id;
3131
if let Some(hir_id) = self.tcx().hir().as_local_hir_id(def_id) {
32-
let fndecl = match self.tcx().hir().get_by_hir_id(hir_id) {
32+
let fndecl = match self.tcx().hir().get(hir_id) {
3333
Node::Item(&hir::Item {
3434
node: hir::ItemKind::Fn(ref fndecl, ..),
3535
..

src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
5252
if let Node::Expr(Expr {
5353
node: Closure(_, _, _, closure_span, None),
5454
..
55-
}) = hir.get_by_hir_id(hir_id) {
55+
}) = hir.get(hir_id) {
5656
let sup_sp = sup_origin.span();
5757
let origin_sp = origin.span();
5858
let mut err = self.tcx().sess.struct_span_err(

src/librustc/infer/error_reporting/note.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
3131
"...so that reference does not outlive borrowed content");
3232
}
3333
infer::ReborrowUpvar(span, ref upvar_id) => {
34-
let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id);
34+
let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id);
3535
err.span_note(span,
3636
&format!("...so that closure can access `{}`", var_name));
3737
}
@@ -163,7 +163,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
163163
err
164164
}
165165
infer::ReborrowUpvar(span, ref upvar_id) => {
166-
let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id);
166+
let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id);
167167
let mut err = struct_span_err!(self.tcx.sess,
168168
span,
169169
E0313,

src/librustc/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ pub enum SubregionOrigin<'tcx> {
265265
DerefPointer(Span),
266266

267267
/// Closure bound must not outlive captured variables
268-
ClosureCapture(Span, ast::NodeId),
268+
ClosureCapture(Span, hir::HirId),
269269

270270
/// Index into slice must be within its lifetime
271271
IndexSlice(Span),

src/librustc/infer/opaque_types/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -945,8 +945,8 @@ pub fn may_define_existential_type(
945945
let mut hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
946946
trace!(
947947
"may_define_existential_type(def={:?}, opaque_node={:?})",
948-
tcx.hir().get_by_hir_id(hir_id),
949-
tcx.hir().get_by_hir_id(opaque_hir_id)
948+
tcx.hir().get(hir_id),
949+
tcx.hir().get(opaque_hir_id)
950950
);
951951

952952
// Named existential types can be defined by any siblings or children of siblings.

src/librustc/middle/liveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
16301630
);
16311631

16321632
if self.ir.variable_is_shorthand(var) {
1633-
if let Node::Binding(pat) = self.ir.tcx.hir().get_by_hir_id(hir_id) {
1633+
if let Node::Binding(pat) = self.ir.tcx.hir().get(hir_id) {
16341634
// Handle `ref` and `ref mut`.
16351635
let spans = spans.iter()
16361636
.map(|_span| (pat.span, format!("{}: _", name)))

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl MutabilityCategory {
344344
tables: &ty::TypeckTables<'_>,
345345
id: hir::HirId,
346346
) -> MutabilityCategory {
347-
let ret = match tcx.hir().get_by_hir_id(id) {
347+
let ret = match tcx.hir().get(id) {
348348
Node::Binding(p) => match p.node {
349349
PatKind::Binding(..) => {
350350
let bm = *tables.pat_binding_modes()

src/librustc/middle/region.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl Scope {
190190
}
191191
let span = tcx.hir().span(hir_id);
192192
if let ScopeData::Remainder(first_statement_index) = self.data {
193-
if let Node::Block(ref blk) = tcx.hir().get_by_hir_id(hir_id) {
193+
if let Node::Block(ref blk) = tcx.hir().get(hir_id) {
194194
// Want span for scope starting after the
195195
// indexed statement and ending at end of
196196
// `blk`; reuse span of `blk` and shift `lo`
@@ -1368,7 +1368,7 @@ fn region_scope_tree<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ScopeTree
13681368
// If the item is an associated const or a method,
13691369
// record its impl/trait parent, as it can also have
13701370
// lifetime parameters free in this body.
1371-
match tcx.hir().get_by_hir_id(id) {
1371+
match tcx.hir().get(id) {
13721372
Node::ImplItem(_) |
13731373
Node::TraitItem(_) => {
13741374
visitor.scope_tree.root_parent = Some(tcx.hir().get_parent_item(id));

src/librustc/middle/resolve_lifetime.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14881488
}
14891489
}
14901490
};
1491-
if let Node::Lifetime(hir_lifetime) = self.tcx.hir().get_by_hir_id(lifetime.hir_id) {
1491+
if let Node::Lifetime(hir_lifetime) = self.tcx.hir().get(lifetime.hir_id) {
14921492
if let Some(parent) = self.tcx.hir().find_by_hir_id(
14931493
self.tcx.hir().get_parent_item(hir_lifetime.hir_id))
14941494
{
@@ -1569,7 +1569,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15691569
Some(LifetimeUseSet::One(lifetime)) => {
15701570
let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap();
15711571
debug!("hir id first={:?}", hir_id);
1572-
if let Some((id, span, name)) = match self.tcx.hir().get_by_hir_id(hir_id) {
1572+
if let Some((id, span, name)) = match self.tcx.hir().get(hir_id) {
15731573
Node::Lifetime(hir_lifetime) => Some((
15741574
hir_lifetime.hir_id,
15751575
hir_lifetime.span,
@@ -1620,7 +1620,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
16201620
}
16211621
None => {
16221622
let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap();
1623-
if let Some((id, span, name)) = match self.tcx.hir().get_by_hir_id(hir_id) {
1623+
if let Some((id, span, name)) = match self.tcx.hir().get(hir_id) {
16241624
Node::Lifetime(hir_lifetime) => Some((
16251625
hir_lifetime.hir_id,
16261626
hir_lifetime.span,
@@ -1823,7 +1823,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
18231823
// Do not free early-bound regions, only late-bound ones.
18241824
} else if let Some(body_id) = outermost_body {
18251825
let fn_id = self.tcx.hir().body_owner(body_id);
1826-
match self.tcx.hir().get_by_hir_id(fn_id) {
1826+
match self.tcx.hir().get(fn_id) {
18271827
Node::Item(&hir::Item {
18281828
node: hir::ItemKind::Fn(..),
18291829
..
@@ -2052,7 +2052,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
20522052
let mut assoc_item_kind = None;
20532053
let mut impl_self = None;
20542054
let parent = self.tcx.hir().get_parent_node_by_hir_id(output.hir_id);
2055-
let body = match self.tcx.hir().get_by_hir_id(parent) {
2055+
let body = match self.tcx.hir().get(parent) {
20562056
// `fn` definitions and methods.
20572057
Node::Item(&hir::Item {
20582058
node: hir::ItemKind::Fn(.., body),

src/librustc/middle/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ impl<'tcx> TyCtxt<'tcx> {
580580

581581
let mut diag = self.struct_span_lint_hir(lint, id, span, &msg);
582582
if let Some(suggestion) = suggestion {
583-
if let hir::Node::Expr(_) = self.hir().get_by_hir_id(id) {
583+
if let hir::Node::Expr(_) = self.hir().get(id) {
584584
diag.span_suggestion(
585585
span,
586586
"replace the use of the deprecated item",

src/librustc/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2573,7 +2573,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
25732573

25742574
if let Some(upvars) = tcx.upvars(def_id) {
25752575
for (&var_id, place) in upvars.keys().zip(places) {
2576-
let var_name = tcx.hir().name_by_hir_id(var_id);
2576+
let var_name = tcx.hir().name(var_id);
25772577
struct_fmt.field(&var_name.as_str(), place);
25782578
}
25792579
}
@@ -2592,7 +2592,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
25922592

25932593
if let Some(upvars) = tcx.upvars(def_id) {
25942594
for (&var_id, place) in upvars.keys().zip(places) {
2595-
let var_name = tcx.hir().name_by_hir_id(var_id);
2595+
let var_name = tcx.hir().name(var_id);
25962596
struct_fmt.field(&var_name.as_str(), place);
25972597
}
25982598
}

src/librustc/traits/error_reporting.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -937,9 +937,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
937937
code: &ObligationCauseCode<'tcx>,
938938
err: &mut DiagnosticBuilder<'tcx>,
939939
) {
940-
if let &ObligationCauseCode::VariableType(node_id) = code {
941-
let parent_node = self.tcx.hir().get_parent_node(node_id);
942-
if let Some(Node::Local(ref local)) = self.tcx.hir().find(parent_node) {
940+
if let &ObligationCauseCode::VariableType(hir_id) = code {
941+
let parent_node = self.tcx.hir().get_parent_node_by_hir_id(hir_id);
942+
if let Some(Node::Local(ref local)) = self.tcx.hir().find_by_hir_id(parent_node) {
943943
if let Some(ref expr) = local.init {
944944
if let hir::ExprKind::Index(_, _) = expr.node {
945945
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(expr.span) {

src/librustc/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub enum ObligationCauseCode<'tcx> {
188188
/// S { ... } must be Sized
189189
StructInitializerSized,
190190
/// Type of each variable must be Sized
191-
VariableType(ast::NodeId),
191+
VariableType(hir::HirId),
192192
/// Argument type must be Sized
193193
SizedArgumentType,
194194
/// Return type must be Sized

0 commit comments

Comments
 (0)