Skip to content

Commit cadb47c

Browse files
authored
Rollup merge of rust-lang#59068 - ljedrz:kill_off_NodeId_stragglers, r=Zoxc
HirIdification: kill off NodeId stragglers The final stages of HirIdification (rust-lang#57578). This PR, along with rust-lang#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 657cb3f + 584d61a commit cadb47c

File tree

17 files changed

+43
-75
lines changed

17 files changed

+43
-75
lines changed

src/librustc/hir/lowering.rs

+4-5
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
}
@@ -2967,6 +2964,7 @@ impl<'a> LoweringContext<'a> {
29672964
// method, it will not be considered an in-band
29682965
// lifetime to be added, but rather a reference to a
29692966
// parent lifetime.
2967+
let lowered_trait_impl_id = self.lower_node_id(id).hir_id;
29702968
let (generics, (trait_ref, lowered_ty)) = self.add_in_band_defs(
29712969
ast_generics,
29722970
def_id,
@@ -2978,7 +2976,8 @@ impl<'a> LoweringContext<'a> {
29782976

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

src/librustc/hir/map/collector.rs

-1
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

+1-13
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

+1-2
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

+2-2
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

+2-2
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

+3-6
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

+3-5
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

+2-6
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

+2-2
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

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);

src/librustc_typeck/coherence/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
3737
{
3838
if Some(self.trait_def_id) == trait_def_id {
3939
for &impl_id in self.tcx.hir().trait_impls(self.trait_def_id) {
40-
let impl_def_id = self.tcx.hir().local_def_id(impl_id);
40+
let impl_def_id = self.tcx.hir().local_def_id_from_hir_id(impl_id);
4141
f(self.tcx, impl_def_id);
4242
}
4343
}

0 commit comments

Comments
 (0)