Skip to content

Commit 00b74e5

Browse files
committed
hir: remove NodeId from Lifetime and Ty
1 parent 904a91c commit 00b74e5

File tree

13 files changed

+71
-82
lines changed

13 files changed

+71
-82
lines changed

src/librustc/hir/lowering.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,9 +1350,8 @@ impl<'a> LoweringContext<'a> {
13501350
TyKind::Mac(_) => panic!("TyMac should have been expanded by now."),
13511351
};
13521352

1353-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(t.id);
1353+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(t.id);
13541354
hir::Ty {
1355-
id: node_id,
13561355
node: kind,
13571356
span: t.span,
13581357
hir_id,
@@ -1533,9 +1532,8 @@ impl<'a> LoweringContext<'a> {
15331532
&& !self.already_defined_lifetimes.contains(&name) {
15341533
self.already_defined_lifetimes.insert(name);
15351534

1536-
let LoweredNodeId { node_id, hir_id } = self.context.next_id();
1535+
let LoweredNodeId { node_id: _, hir_id } = self.context.next_id();
15371536
self.output_lifetimes.push(hir::GenericArg::Lifetime(hir::Lifetime {
1538-
id: node_id,
15391537
hir_id,
15401538
span: lifetime.span,
15411539
name,
@@ -1980,8 +1978,8 @@ impl<'a> LoweringContext<'a> {
19801978
.map(|ty| this.lower_ty_direct(ty, ImplTraitContext::disallowed()))
19811979
.collect();
19821980
let mk_tup = |this: &mut Self, tys, span| {
1983-
let LoweredNodeId { node_id, hir_id } = this.next_id();
1984-
hir::Ty { node: hir::TyKind::Tup(tys), id: node_id, hir_id, span }
1981+
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
1982+
hir::Ty { node: hir::TyKind::Tup(tys), hir_id, span }
19851983
};
19861984
let LoweredNodeId { node_id, hir_id } = this.next_id();
19871985

@@ -2318,9 +2316,8 @@ impl<'a> LoweringContext<'a> {
23182316
this.lower_ty(ty, ImplTraitContext::Existential(Some(fn_def_id)))
23192317
}
23202318
FunctionRetTy::Default(span) => {
2321-
let LoweredNodeId { node_id, hir_id } = this.next_id();
2319+
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
23222320
P(hir::Ty {
2323-
id: node_id,
23242321
hir_id,
23252322
node: hir::TyKind::Tup(hir_vec![]),
23262323
span: *span,
@@ -2362,17 +2359,16 @@ impl<'a> LoweringContext<'a> {
23622359
];
23632360

23642361
if let Some((name, span)) = bound_lifetime {
2365-
let LoweredNodeId { node_id, hir_id } = this.next_id();
2362+
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
23662363
bounds.push(hir::GenericBound::Outlives(
2367-
hir::Lifetime { id: node_id, hir_id, name, span }));
2364+
hir::Lifetime { hir_id, name, span }));
23682365
}
23692366

23702367
hir::HirVec::from(bounds)
23712368
});
23722369

2373-
let LoweredNodeId { node_id, hir_id } = self.next_id();
2370+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
23742371
let impl_trait_ty = P(hir::Ty {
2375-
id: node_id,
23762372
node: impl_trait_ty,
23772373
span,
23782374
hir_id,
@@ -2431,10 +2427,9 @@ impl<'a> LoweringContext<'a> {
24312427
span: Span,
24322428
name: hir::LifetimeName,
24332429
) -> hir::Lifetime {
2434-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id);
2430+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id);
24352431

24362432
hir::Lifetime {
2437-
id: node_id,
24382433
hir_id,
24392434
span,
24402435
name: name,
@@ -5108,7 +5103,6 @@ impl<'a> LoweringContext<'a> {
51085103
_ => hir::TyKind::Path(qpath),
51095104
};
51105105
hir::Ty {
5111-
id: id.node_id,
51125106
hir_id: id.hir_id,
51135107
node,
51145108
span,
@@ -5124,9 +5118,8 @@ impl<'a> LoweringContext<'a> {
51245118
// `'f`.
51255119
AnonymousLifetimeMode::CreateParameter => {
51265120
let fresh_name = self.collect_fresh_in_band_lifetime(span);
5127-
let LoweredNodeId { node_id, hir_id } = self.next_id();
5121+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
51285122
hir::Lifetime {
5129-
id: node_id,
51305123
hir_id,
51315124
span,
51325125
name: hir::LifetimeName::Param(fresh_name),
@@ -5227,10 +5220,9 @@ impl<'a> LoweringContext<'a> {
52275220
}
52285221

52295222
fn new_implicit_lifetime(&mut self, span: Span) -> hir::Lifetime {
5230-
let LoweredNodeId { node_id, hir_id } = self.next_id();
5223+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
52315224

52325225
hir::Lifetime {
5233-
id: node_id,
52345226
hir_id,
52355227
span,
52365228
name: hir::LifetimeName::Implicit,

src/librustc/hir/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId::MAX;
151151

152152
#[derive(Clone, RustcEncodable, RustcDecodable, Copy)]
153153
pub struct Lifetime {
154-
pub id: NodeId,
155154
pub hir_id: HirId,
156155
pub span: Span,
157156

@@ -272,7 +271,7 @@ impl fmt::Debug for Lifetime {
272271
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
273272
write!(f,
274273
"lifetime({}: {})",
275-
self.id,
274+
self.hir_id,
276275
print::to_string(print::NO_ANN, |s| s.print_lifetime(self)))
277276
}
278277
}
@@ -417,10 +416,10 @@ impl GenericArg {
417416
}
418417
}
419418

420-
pub fn id(&self) -> NodeId {
419+
pub fn id(&self) -> HirId {
421420
match self {
422-
GenericArg::Lifetime(l) => l.id,
423-
GenericArg::Type(t) => t.id,
421+
GenericArg::Lifetime(l) => l.hir_id,
422+
GenericArg::Type(t) => t.hir_id,
424423
GenericArg::Const(c) => c.value.id,
425424
}
426425
}
@@ -1760,7 +1759,6 @@ pub struct TypeBinding {
17601759

17611760
#[derive(Clone, RustcEncodable, RustcDecodable)]
17621761
pub struct Ty {
1763-
pub id: NodeId,
17641762
pub node: TyKind,
17651763
pub span: Span,
17661764
pub hir_id: HirId,

src/librustc/ich/impls_hir.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ impl_stable_hash_for!(struct ast::Label {
158158
});
159159

160160
impl_stable_hash_for!(struct hir::Lifetime {
161-
id,
162161
hir_id,
163162
span,
164163
name
@@ -318,7 +317,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Ty {
318317
hasher: &mut StableHasher<W>) {
319318
hcx.while_hashing_hir_bodies(true, |hcx| {
320319
let hir::Ty {
321-
id: _,
322320
hir_id: _,
323321
ref node,
324322
ref span,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
101101

102102
let (span_1, span_2, main_label, span_label) = match (sup_is_ret_type, sub_is_ret_type) {
103103
(None, None) => {
104-
let (main_label_1, span_label_1) = if ty_sup.id == ty_sub.id {
104+
let (main_label_1, span_label_1) = if ty_sup.hir_id == ty_sub.hir_id {
105105
(
106106
"this type is declared with multiple lifetimes...".to_owned(),
107107
"...but data with one lifetime flows into the other here".to_owned()

src/librustc/middle/resolve_lifetime.rs

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt};
1313

1414
use crate::rustc::lint;
1515
use crate::session::Session;
16-
use crate::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, NodeMap, NodeSet};
16+
use crate::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, HirIdMap, NodeMap, NodeSet};
1717
use errors::{Applicability, DiagnosticBuilder};
1818
use rustc_data_structures::sync::Lrc;
1919
use std::borrow::Cow;
@@ -151,7 +151,7 @@ impl Region {
151151
if let Region::EarlyBound(index, _, _) = self {
152152
params
153153
.nth(index as usize)
154-
.and_then(|lifetime| map.defs.get(&lifetime.id).cloned())
154+
.and_then(|lifetime| map.defs.get(&lifetime.hir_id).cloned())
155155
} else {
156156
Some(self)
157157
}
@@ -195,7 +195,7 @@ pub type ObjectLifetimeDefault = Set1<Region>;
195195
struct NamedRegionMap {
196196
// maps from every use of a named (not anonymous) lifetime to a
197197
// `Region` describing how that region is bound
198-
pub defs: NodeMap<Region>,
198+
pub defs: HirIdMap<Region>,
199199

200200
// the set of lifetime def ids that are late-bound; a region can
201201
// be late-bound if (a) it does NOT appear in a where-clause and
@@ -385,8 +385,7 @@ fn resolve_lifetimes<'tcx>(
385385

386386
let mut rl = ResolveLifetimes::default();
387387

388-
for (k, v) in named_region_map.defs {
389-
let hir_id = tcx.hir().node_to_hir_id(k);
388+
for (hir_id, v) in named_region_map.defs {
390389
let map = rl.defs.entry(hir_id.owner_local_def_id()).or_default();
391390
Lrc::get_mut(map).unwrap().insert(hir_id.local_id, v);
392391
}
@@ -570,7 +569,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
570569
}
571570

572571
fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
573-
debug!("visit_ty: id={:?} ty={:?}", ty.id, ty);
572+
debug!("visit_ty: id={:?} ty={:?}", ty.hir_id, ty);
574573
match ty.node {
575574
hir::TyKind::BareFn(ref c) => {
576575
let next_early_index = self.next_early_index();
@@ -629,7 +628,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
629628
hir::TyKind::Rptr(ref lifetime_ref, ref mt) => {
630629
self.visit_lifetime(lifetime_ref);
631630
let scope = Scope::ObjectLifetimeDefault {
632-
lifetime: self.map.defs.get(&lifetime_ref.id).cloned(),
631+
lifetime: self.map.defs.get(&lifetime_ref.hir_id).cloned(),
633632
s: self.scope,
634633
};
635634
self.with(scope, |_, this| this.visit_ty(&mt.ty));
@@ -672,7 +671,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
672671
// and ban them. Type variables instantiated inside binders aren't
673672
// well-supported at the moment, so this doesn't work.
674673
// In the future, this should be fixed and this error should be removed.
675-
let def = self.map.defs.get(&lifetime.id).cloned();
674+
let def = self.map.defs.get(&lifetime.hir_id).cloned();
676675
if let Some(Region::LateBound(_, def_id, _)) = def {
677676
if let Some(node_id) = self.tcx.hir().as_local_node_id(def_id) {
678677
// Ensure that the parent of the def is an item, not HRTB
@@ -1501,8 +1500,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15011500
}
15021501
}
15031502
};
1504-
if let Node::Lifetime(hir_lifetime) = self.tcx.hir().get(lifetime.id) {
1505-
if let Some(parent) = self.tcx.hir().find(self.tcx.hir().get_parent(hir_lifetime.id)) {
1503+
if let Node::Lifetime(hir_lifetime) = self.tcx.hir().get_by_hir_id(lifetime.hir_id) {
1504+
if let Some(parent) = self.tcx.hir().find_by_hir_id(
1505+
self.tcx.hir().get_parent_item(hir_lifetime.hir_id))
1506+
{
15061507
match parent {
15071508
Node::Item(item) => {
15081509
if let hir::ItemKind::Fn(decl, _, _, _) = &item.node {
@@ -1582,22 +1583,22 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15821583
debug!("node id first={:?}", node_id);
15831584
if let Some((id, span, name)) = match self.tcx.hir().get(node_id) {
15841585
Node::Lifetime(hir_lifetime) => Some((
1585-
hir_lifetime.id,
1586+
hir_lifetime.hir_id,
15861587
hir_lifetime.span,
15871588
hir_lifetime.name.ident(),
15881589
)),
15891590
Node::GenericParam(param) => {
1590-
Some((param.id, param.span, param.name.ident()))
1591+
Some((param.hir_id, param.span, param.name.ident()))
15911592
}
15921593
_ => None,
15931594
} {
1594-
debug!("id = {:?} span = {:?} name = {:?}", node_id, span, name);
1595+
debug!("id = {:?} span = {:?} name = {:?}", id, span, name);
15951596

15961597
if name == keywords::UnderscoreLifetime.ident() {
15971598
continue;
15981599
}
15991600

1600-
let mut err = self.tcx.struct_span_lint_node(
1601+
let mut err = self.tcx.struct_span_lint_hir(
16011602
lint::builtin::SINGLE_USE_LIFETIMES,
16021603
id,
16031604
span,
@@ -1622,17 +1623,17 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
16221623
let node_id = self.tcx.hir().as_local_node_id(def_id).unwrap();
16231624
if let Some((id, span, name)) = match self.tcx.hir().get(node_id) {
16241625
Node::Lifetime(hir_lifetime) => Some((
1625-
hir_lifetime.id,
1626+
hir_lifetime.hir_id,
16261627
hir_lifetime.span,
16271628
hir_lifetime.name.ident(),
16281629
)),
16291630
Node::GenericParam(param) => {
1630-
Some((param.id, param.span, param.name.ident()))
1631+
Some((param.hir_id, param.span, param.name.ident()))
16311632
}
16321633
_ => None,
16331634
} {
1634-
debug!("id ={:?} span = {:?} name = {:?}", node_id, span, name);
1635-
let mut err = self.tcx.struct_span_lint_node(
1635+
debug!("id ={:?} span = {:?} name = {:?}", id, span, name);
1636+
let mut err = self.tcx.struct_span_lint_hir(
16361637
lint::builtin::UNUSED_LIFETIMES,
16371638
id,
16381639
span,
@@ -2049,8 +2050,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
20492050
// and whether there's a `self` argument (treated specially).
20502051
let mut assoc_item_kind = None;
20512052
let mut impl_self = None;
2052-
let parent = self.tcx.hir().get_parent_node(output.id);
2053-
let body = match self.tcx.hir().get(parent) {
2053+
let parent = self.tcx.hir().get_parent_node_by_hir_id(output.hir_id);
2054+
let body = match self.tcx.hir().get_by_hir_id(parent) {
20542055
// `fn` definitions and methods.
20552056
Node::Item(&hir::Item {
20562057
node: hir::ItemKind::Fn(.., body),
@@ -2063,12 +2064,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
20632064
}) => {
20642065
if let hir::ItemKind::Trait(.., ref trait_items) = self.tcx
20652066
.hir()
2066-
.expect_item(self.tcx.hir().get_parent(parent))
2067+
.expect_item_by_hir_id(self.tcx.hir().get_parent_item(parent))
20672068
.node
20682069
{
2070+
let parent_node_id = self.tcx.hir().hir_to_node_id(parent);
20692071
assoc_item_kind = trait_items
20702072
.iter()
2071-
.find(|ti| ti.id.node_id == parent)
2073+
.find(|ti| ti.id.node_id == parent_node_id)
20722074
.map(|ti| ti.kind);
20732075
}
20742076
match *m {
@@ -2083,13 +2085,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
20832085
}) => {
20842086
if let hir::ItemKind::Impl(.., ref self_ty, ref impl_items) = self.tcx
20852087
.hir()
2086-
.expect_item(self.tcx.hir().get_parent(parent))
2088+
.expect_item_by_hir_id(self.tcx.hir().get_parent_item(parent))
20872089
.node
20882090
{
20892091
impl_self = Some(self_ty);
2092+
let parent_node_id = self.tcx.hir().hir_to_node_id(parent);
20902093
assoc_item_kind = impl_items
20912094
.iter()
2092-
.find(|ii| ii.id.node_id == parent)
2095+
.find(|ii| ii.id.node_id == parent_node_id)
20932096
.map(|ii| ii.kind);
20942097
}
20952098
Some(body)
@@ -2143,7 +2146,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
21432146
if let hir::TyKind::Rptr(lifetime_ref, ref mt) = inputs[0].node {
21442147
if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = mt.ty.node {
21452148
if is_self_ty(path.def) {
2146-
if let Some(&lifetime) = self.map.defs.get(&lifetime_ref.id) {
2149+
if let Some(&lifetime) = self.map.defs.get(&lifetime_ref.hir_id) {
21472150
let scope = Scope::Elision {
21482151
elide: Elide::Exact(lifetime),
21492152
s: self.scope,
@@ -2262,7 +2265,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
22622265
}
22632266

22642267
fn visit_lifetime(&mut self, lifetime_ref: &hir::Lifetime) {
2265-
if let Some(&lifetime) = self.map.defs.get(&lifetime_ref.id) {
2268+
if let Some(&lifetime) = self.map.defs.get(&lifetime_ref.hir_id) {
22662269
match lifetime {
22672270
Region::LateBound(debruijn, _, _) | Region::LateBoundAnon(debruijn, _)
22682271
if debruijn < self.outer_index =>
@@ -2653,7 +2656,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
26532656
}
26542657

26552658
fn insert_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime, def: Region) {
2656-
if lifetime_ref.id == ast::DUMMY_NODE_ID {
2659+
if lifetime_ref.hir_id == hir::DUMMY_HIR_ID {
26572660
span_bug!(
26582661
lifetime_ref.span,
26592662
"lifetime reference not renumbered, \
@@ -2663,11 +2666,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
26632666

26642667
debug!(
26652668
"insert_lifetime: {} resolved to {:?} span={:?}",
2666-
self.tcx.hir().node_to_string(lifetime_ref.id),
2669+
self.tcx.hir().hir_to_string(lifetime_ref.hir_id),
26672670
def,
26682671
self.tcx.sess.source_map().span_to_string(lifetime_ref.span)
26692672
);
2670-
self.map.defs.insert(lifetime_ref.id, def);
2673+
self.map.defs.insert(lifetime_ref.hir_id, def);
26712674

26722675
match def {
26732676
Region::LateBoundAnon(..) | Region::Static => {
@@ -2699,7 +2702,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
26992702
/// error (esp. around impl trait). In that case, we remove the
27002703
/// entry into `map.defs` so as not to confuse later code.
27012704
fn uninsert_lifetime_on_error(&mut self, lifetime_ref: &'tcx hir::Lifetime, bad_def: Region) {
2702-
let old_value = self.map.defs.remove(&lifetime_ref.id);
2705+
let old_value = self.map.defs.remove(&lifetime_ref.hir_id);
27032706
assert_eq!(old_value, Some(bad_def));
27042707
}
27052708
}

0 commit comments

Comments
 (0)