Skip to content

Commit 0633c55

Browse files
committed
Auto merge of #59068 - ljedrz:kill_off_NodeId_stragglers, r=Zoxc
HirIdification: kill off NodeId stragglers The final stages of HirIdification (#57578). This PR, along with #59042, should finalize the HirIdification process (at least the more straightforward bits). - replace `NodeId` with `HirId` in `trait_impls` - remove all `NodeId`s from `borrowck` - remove all `NodeId`s from `typeck` - remove all `NodeId`s from `mir` - remove `trait_auto_impl` (unused) I would be cool to also remove `NodeId` from `hir::def::Def`, `middle::privacy::AccessLevel` and `hir::ItemId`, but I don't know if this is feasible. I'll be happy to do more if I've missed anything.
2 parents 0f118f6 + 584d61a commit 0633c55

File tree

17 files changed

+43
-75
lines changed

17 files changed

+43
-75
lines changed

src/librustc/hir/lowering.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ pub struct LoweringContext<'a> {
8989
bodies: BTreeMap<hir::BodyId, hir::Body>,
9090
exported_macros: Vec<hir::MacroDef>,
9191

92-
trait_impls: BTreeMap<DefId, Vec<NodeId>>,
93-
trait_auto_impl: BTreeMap<DefId, NodeId>,
92+
trait_impls: BTreeMap<DefId, Vec<hir::HirId>>,
9493

9594
modules: BTreeMap<NodeId, hir::ModuleItems>,
9695

@@ -233,7 +232,6 @@ pub fn lower_crate(
233232
impl_items: BTreeMap::new(),
234233
bodies: BTreeMap::new(),
235234
trait_impls: BTreeMap::new(),
236-
trait_auto_impl: BTreeMap::new(),
237235
modules: BTreeMap::new(),
238236
exported_macros: Vec::new(),
239237
catch_scopes: Vec::new(),
@@ -514,7 +512,6 @@ impl<'a> LoweringContext<'a> {
514512
bodies: self.bodies,
515513
body_ids,
516514
trait_impls: self.trait_impls,
517-
trait_auto_impl: self.trait_auto_impl,
518515
modules: self.modules,
519516
}
520517
}
@@ -2968,6 +2965,7 @@ impl<'a> LoweringContext<'a> {
29682965
// method, it will not be considered an in-band
29692966
// lifetime to be added, but rather a reference to a
29702967
// parent lifetime.
2968+
let lowered_trait_impl_id = self.lower_node_id(id).hir_id;
29712969
let (generics, (trait_ref, lowered_ty)) = self.add_in_band_defs(
29722970
ast_generics,
29732971
def_id,
@@ -2979,7 +2977,8 @@ impl<'a> LoweringContext<'a> {
29792977

29802978
if let Some(ref trait_ref) = trait_ref {
29812979
if let Def::Trait(def_id) = trait_ref.path.def {
2982-
this.trait_impls.entry(def_id).or_default().push(id);
2980+
this.trait_impls.entry(def_id).or_default().push(
2981+
lowered_trait_impl_id);
29832982
}
29842983
}
29852984

src/librustc/hir/map/collector.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
121121
impl_items: _,
122122
bodies: _,
123123
trait_impls: _,
124-
trait_auto_impl: _,
125124
body_ids: _,
126125
modules: _,
127126
} = *krate;

src/librustc/hir/map/mod.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -557,26 +557,14 @@ impl<'hir> Map<'hir> {
557557
}
558558
}
559559

560-
pub fn trait_impls(&self, trait_did: DefId) -> &'hir [NodeId] {
560+
pub fn trait_impls(&self, trait_did: DefId) -> &'hir [HirId] {
561561
self.dep_graph.read(DepNode::new_no_params(DepKind::AllLocalTraitImpls));
562562

563563
// N.B., intentionally bypass `self.forest.krate()` so that we
564564
// do not trigger a read of the whole krate here
565565
self.forest.krate.trait_impls.get(&trait_did).map_or(&[], |xs| &xs[..])
566566
}
567567

568-
pub fn trait_auto_impl(&self, trait_did: DefId) -> Option<NodeId> {
569-
self.dep_graph.read(DepNode::new_no_params(DepKind::AllLocalTraitImpls));
570-
571-
// N.B., intentionally bypass `self.forest.krate()` so that we
572-
// do not trigger a read of the whole krate here
573-
self.forest.krate.trait_auto_impl.get(&trait_did).cloned()
574-
}
575-
576-
pub fn trait_is_auto(&self, trait_did: DefId) -> bool {
577-
self.trait_auto_impl(trait_did).is_some()
578-
}
579-
580568
/// Gets the attributes on the crate. This is preferable to
581569
/// invoking `krate.attrs` because it registers a tighter
582570
/// dep-graph access.

src/librustc/hir/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,7 @@ pub struct Crate {
727727
pub trait_items: BTreeMap<TraitItemId, TraitItem>,
728728
pub impl_items: BTreeMap<ImplItemId, ImplItem>,
729729
pub bodies: BTreeMap<BodyId, Body>,
730-
pub trait_impls: BTreeMap<DefId, Vec<NodeId>>,
731-
pub trait_auto_impl: BTreeMap<DefId, NodeId>,
730+
pub trait_impls: BTreeMap<DefId, Vec<HirId>>,
732731

733732
/// A list of the body ids written out in the order in which they
734733
/// appear in the crate. If you're going to process all the bodies

src/librustc/ty/trait_def.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ pub(super) fn trait_impls_of_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
183183
}
184184
}
185185

186-
for &node_id in tcx.hir().trait_impls(trait_id) {
187-
add_impl(tcx.hir().local_def_id(node_id));
186+
for &hir_id in tcx.hir().trait_impls(trait_id) {
187+
add_impl(tcx.hir().local_def_id_from_hir_id(hir_id));
188188
}
189189
}
190190

src/librustc_borrowck/borrowck/gather_loans/lifetime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
//! does not exceed the lifetime of the value being borrowed.
33
44
use crate::borrowck::*;
5+
use rustc::hir::HirId;
56
use rustc::middle::expr_use_visitor as euv;
67
use rustc::middle::mem_categorization as mc;
78
use rustc::middle::mem_categorization::Categorization;
89
use rustc::middle::region;
910
use rustc::ty;
1011

11-
use syntax::ast;
1212
use syntax_pos::Span;
1313
use log::debug;
1414

@@ -51,7 +51,7 @@ struct GuaranteeLifetimeContext<'a, 'tcx: 'a> {
5151
}
5252

5353
impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> {
54-
fn check(&self, cmt: &mc::cmt_<'tcx>, discr_scope: Option<ast::NodeId>) -> R {
54+
fn check(&self, cmt: &mc::cmt_<'tcx>, discr_scope: Option<HirId>) -> R {
5555
//! Main routine. Walks down `cmt` until we find the
5656
//! "guarantor". Reports an error if `self.loan_region` is
5757
//! larger than scope of `cmt`.

src/librustc_borrowck/borrowck/gather_loans/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc::middle::mem_categorization::Categorization;
1414
use rustc::middle::region;
1515
use rustc::ty::{self, TyCtxt};
1616

17-
use syntax::ast;
1817
use syntax_pos::Span;
1918
use rustc::hir;
2019
use log::debug;
@@ -141,8 +140,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> {
141140
assignee_cmt: &mc::cmt_<'tcx>,
142141
_: euv::MutateMode)
143142
{
144-
let node_id = self.bccx.tcx.hir().hir_to_node_id(assignment_id);
145-
self.guarantee_assignment_valid(node_id,
143+
self.guarantee_assignment_valid(assignment_id,
146144
assignment_span,
147145
assignee_cmt);
148146
}
@@ -256,7 +254,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
256254

257255
/// Guarantees that `cmt` is assignable, or reports an error.
258256
fn guarantee_assignment_valid(&mut self,
259-
assignment_id: ast::NodeId,
257+
assignment_id: hir::HirId,
260258
assignment_span: Span,
261259
cmt: &mc::cmt_<'tcx>) {
262260

@@ -290,8 +288,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
290288
self.mark_loan_path_as_mutated(&lp);
291289
}
292290
gather_moves::gather_assignment(self.bccx, &self.move_data,
293-
self.bccx.tcx.hir().node_to_hir_id(assignment_id)
294-
.local_id,
291+
assignment_id.local_id,
295292
assignment_span,
296293
lp);
297294
}

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use std::fmt;
3434
use std::rc::Rc;
3535
use rustc_data_structures::sync::Lrc;
3636
use std::hash::{Hash, Hasher};
37-
use syntax::ast;
3837
use syntax_pos::{MultiSpan, Span};
3938
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
4039
use log::debug;
@@ -399,12 +398,12 @@ pub enum LoanPathElem<'tcx> {
399398
}
400399

401400
fn closure_to_block(closure_id: LocalDefId,
402-
tcx: TyCtxt<'_, '_, '_>) -> ast::NodeId {
401+
tcx: TyCtxt<'_, '_, '_>) -> HirId {
403402
let closure_id = tcx.hir().local_def_id_to_node_id(closure_id);
404403
match tcx.hir().get(closure_id) {
405404
Node::Expr(expr) => match expr.node {
406405
hir::ExprKind::Closure(.., body_id, _, _) => {
407-
tcx.hir().hir_to_node_id(body_id.hir_id)
406+
body_id.hir_id
408407
}
409408
_ => {
410409
bug!("encountered non-closure id: {}", closure_id)
@@ -422,8 +421,7 @@ impl<'a, 'tcx> LoanPath<'tcx> {
422421
}
423422
LpUpvar(upvar_id) => {
424423
let block_id = closure_to_block(upvar_id.closure_expr_id, bccx.tcx);
425-
let hir_id = bccx.tcx.hir().node_to_hir_id(block_id);
426-
region::Scope { id: hir_id.local_id, data: region::ScopeData::Node }
424+
region::Scope { id: block_id.local_id, data: region::ScopeData::Node }
427425
}
428426
LpDowncast(ref base, _) |
429427
LpExtend(ref base, ..) => base.kill_scope(bccx),

src/librustc_mir/borrow_check/nll/universal_regions.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use rustc::util::nodemap::FxHashMap;
2323
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
2424
use rustc_errors::DiagnosticBuilder;
2525
use std::iter;
26-
use syntax::ast;
2726

2827
use super::ToRegionVid;
2928

@@ -200,12 +199,10 @@ impl<'tcx> UniversalRegions<'tcx> {
200199
param_env: ty::ParamEnv<'tcx>,
201200
) -> Self {
202201
let tcx = infcx.tcx;
203-
let mir_node_id = tcx.hir().as_local_node_id(mir_def_id).unwrap();
204-
let mir_hir_id = tcx.hir().node_to_hir_id(mir_node_id);
202+
let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).unwrap();
205203
UniversalRegionsBuilder {
206204
infcx,
207205
mir_def_id,
208-
mir_node_id,
209206
mir_hir_id,
210207
param_env,
211208
}.build()
@@ -370,7 +367,6 @@ struct UniversalRegionsBuilder<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
370367
infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
371368
mir_def_id: DefId,
372369
mir_hir_id: HirId,
373-
mir_node_id: ast::NodeId,
374370
param_env: ty::ParamEnv<'tcx>,
375371
}
376372

@@ -475,7 +471,7 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
475471
let tcx = self.infcx.tcx;
476472
let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id);
477473

478-
match tcx.hir().body_owner_kind(self.mir_node_id) {
474+
match tcx.hir().body_owner_kind_by_hir_id(self.mir_hir_id) {
479475
BodyOwnerKind::Closure |
480476
BodyOwnerKind::Fn => {
481477
let defining_ty = if self.mir_def_id == closure_base_def_id {

src/librustc_mir/build/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
373373
/// finish building it.
374374
guard_context: Vec<GuardFrame>,
375375

376-
/// Maps `NodeId`s of variable bindings to the `Local`s created for them.
376+
/// Maps `HirId`s of variable bindings to the `Local`s created for them.
377377
/// (A match binding can have two locals; the 2nd is for the arm's guard.)
378378
var_indices: HirIdMap<LocalsForNode>,
379379
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
@@ -451,7 +451,7 @@ impl BlockContext {
451451

452452
#[derive(Debug)]
453453
enum LocalsForNode {
454-
/// In the usual case, a `NodeId` for an identifier maps to at most
454+
/// In the usual case, a `HirId` for an identifier maps to at most
455455
/// one `Local` declaration.
456456
One(Local),
457457

0 commit comments

Comments
 (0)