Skip to content

Commit 0ea2271

Browse files
committed
Auto merge of #58836 - ljedrz:begone_NodeId, r=Zoxc
Remove NodeId from even more HIR nodes The next iteration of HirIdification (#57578). Removes `NodeId` from: - [x] `StructField` - [x] `ForeignItem` - [x] `Item` - [x] `Pat` - [x] `FieldPat` - [x] `VariantData` - [x] `ImplItemId` (replaces it with `HirId`) - [x] `TraitItemId` (replaces it with `HirId`)
2 parents fab272e + 299ed9a commit 0ea2271

Some content is hidden

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

60 files changed

+528
-558
lines changed

src/librustc/hir/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
9494
/// Checks any attribute.
9595
fn check_attributes(&self, item: &hir::Item, target: Target) {
9696
if target == Target::Fn || target == Target::Const {
97-
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(item.id));
97+
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id_from_hir_id(item.hir_id));
9898
} else if let Some(a) = item.attrs.iter().find(|a| a.check_name("target_feature")) {
9999
self.tcx.sess.struct_span_err(a.span, "attribute should be applied to a function")
100100
.span_label(item.span, "not a function")

src/librustc/hir/lowering.rs

+37-46
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ impl<'a> LoweringContext<'a> {
469469

470470
fn visit_trait_item(&mut self, item: &'lcx TraitItem) {
471471
self.lctx.with_hir_id_owner(item.id, |lctx| {
472-
let id = hir::TraitItemId { node_id: item.id };
473472
let hir_item = lctx.lower_trait_item(item);
473+
let id = hir::TraitItemId { hir_id: hir_item.hir_id };
474474
lctx.trait_items.insert(id, hir_item);
475475
lctx.modules.get_mut(&lctx.current_module).unwrap().trait_items.insert(id);
476476
});
@@ -480,8 +480,8 @@ impl<'a> LoweringContext<'a> {
480480

481481
fn visit_impl_item(&mut self, item: &'lcx ImplItem) {
482482
self.lctx.with_hir_id_owner(item.id, |lctx| {
483-
let id = hir::ImplItemId { node_id: item.id };
484483
let hir_item = lctx.lower_impl_item(item);
484+
let id = hir::ImplItemId { hir_id: hir_item.hir_id };
485485
lctx.impl_items.insert(id, hir_item);
486486
lctx.modules.get_mut(&lctx.current_module).unwrap().impl_items.insert(id);
487487
});
@@ -1414,7 +1414,6 @@ impl<'a> LoweringContext<'a> {
14141414

14151415
trace!("exist ty def index: {:#?}", exist_ty_def_index);
14161416
let exist_ty_item = hir::Item {
1417-
id: exist_ty_id.node_id,
14181417
hir_id: exist_ty_id.hir_id,
14191418
ident: keywords::Invalid.ident(),
14201419
attrs: Default::default(),
@@ -2675,35 +2674,33 @@ impl<'a> LoweringContext<'a> {
26752674
fn lower_variant_data(&mut self, vdata: &VariantData) -> hir::VariantData {
26762675
match *vdata {
26772676
VariantData::Struct(ref fields, id) => {
2678-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id);
2677+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id);
26792678

26802679
hir::VariantData::Struct(
26812680
fields
26822681
.iter()
26832682
.enumerate()
26842683
.map(|f| self.lower_struct_field(f))
26852684
.collect(),
2686-
node_id,
26872685
hir_id,
26882686
)
26892687
},
26902688
VariantData::Tuple(ref fields, id) => {
2691-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id);
2689+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id);
26922690

26932691
hir::VariantData::Tuple(
26942692
fields
26952693
.iter()
26962694
.enumerate()
26972695
.map(|f| self.lower_struct_field(f))
26982696
.collect(),
2699-
node_id,
27002697
hir_id,
27012698
)
27022699
},
27032700
VariantData::Unit(id) => {
2704-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id);
2701+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id);
27052702

2706-
hir::VariantData::Unit(node_id, hir_id)
2703+
hir::VariantData::Unit(hir_id)
27072704
},
27082705
}
27092706
}
@@ -2743,11 +2740,10 @@ impl<'a> LoweringContext<'a> {
27432740
}
27442741

27452742
fn lower_struct_field(&mut self, (index, f): (usize, &StructField)) -> hir::StructField {
2746-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(f.id);
2743+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(f.id);
27472744

27482745
hir::StructField {
27492746
span: f.span,
2750-
id: node_id,
27512747
hir_id,
27522748
ident: match f.ident {
27532749
Some(ident) => ident,
@@ -3129,7 +3125,6 @@ impl<'a> LoweringContext<'a> {
31293125
this.insert_item(
31303126
new_id.node_id,
31313127
hir::Item {
3132-
id: new_id.node_id,
31333128
hir_id: new_id.hir_id,
31343129
ident,
31353130
attrs: attrs.clone(),
@@ -3235,7 +3230,6 @@ impl<'a> LoweringContext<'a> {
32353230
this.insert_item(
32363231
new_id,
32373232
hir::Item {
3238-
id: new_id,
32393233
hir_id: new_hir_id,
32403234
ident,
32413235
attrs: attrs.clone(),
@@ -3369,7 +3363,7 @@ impl<'a> LoweringContext<'a> {
33693363
TraitItemKind::Macro(..) => unimplemented!(),
33703364
};
33713365
hir::TraitItemRef {
3372-
id: hir::TraitItemId { node_id: i.id },
3366+
id: hir::TraitItemId { hir_id: self.lower_node_id(i.id).hir_id },
33733367
ident: i.ident,
33743368
span: i.span,
33753369
defaultness: self.lower_defaultness(Defaultness::Default, has_default),
@@ -3433,7 +3427,7 @@ impl<'a> LoweringContext<'a> {
34333427

34343428
fn lower_impl_item_ref(&mut self, i: &ImplItem) -> hir::ImplItemRef {
34353429
hir::ImplItemRef {
3436-
id: hir::ImplItemId { node_id: i.id },
3430+
id: hir::ImplItemId { hir_id: self.lower_node_id(i.id).hir_id },
34373431
ident: i.ident,
34383432
span: i.span,
34393433
vis: self.lower_visibility(&i.vis, Some(i.id)),
@@ -3535,10 +3529,9 @@ impl<'a> LoweringContext<'a> {
35353529

35363530
let node = self.lower_item_kind(i.id, &mut ident, &attrs, &mut vis, &i.node);
35373531

3538-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id);
3532+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(i.id);
35393533

35403534
Some(hir::Item {
3541-
id: node_id,
35423535
hir_id,
35433536
ident,
35443537
attrs,
@@ -3552,7 +3545,6 @@ impl<'a> LoweringContext<'a> {
35523545
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id);
35533546
let def_id = self.resolver.definitions().local_def_id(node_id);
35543547
hir::ForeignItem {
3555-
id: node_id,
35563548
hir_id,
35573549
ident: i.ident,
35583550
attrs: self.lower_attrs(&i.attrs),
@@ -3746,12 +3738,11 @@ impl<'a> LoweringContext<'a> {
37463738
let fs = fields
37473739
.iter()
37483740
.map(|f| {
3749-
let LoweredNodeId { node_id, hir_id } = self.next_id();
3741+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
37503742

37513743
Spanned {
37523744
span: f.span,
37533745
node: hir::FieldPat {
3754-
id: node_id,
37553746
hir_id,
37563747
ident: f.node.ident,
37573748
pat: self.lower_pat(&f.node.pat),
@@ -3783,9 +3774,8 @@ impl<'a> LoweringContext<'a> {
37833774
PatKind::Mac(_) => panic!("Shouldn't exist here"),
37843775
};
37853776

3786-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(p.id);
3777+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(p.id);
37873778
P(hir::Pat {
3788-
id: node_id,
37893779
hir_id,
37903780
node,
37913781
span: p.span,
@@ -4359,7 +4349,7 @@ impl<'a> LoweringContext<'a> {
43594349
let iter = self.str_to_ident("iter");
43604350

43614351
let next_ident = self.str_to_ident("__next");
4362-
let next_pat = self.pat_ident_binding_mode(
4352+
let (next_pat, next_pat_nid) = self.pat_ident_binding_mode(
43634353
desugared_span,
43644354
next_ident,
43654355
hir::BindingAnnotation::Mutable,
@@ -4368,9 +4358,9 @@ impl<'a> LoweringContext<'a> {
43684358
// `::std::option::Option::Some(val) => next = val`
43694359
let pat_arm = {
43704360
let val_ident = self.str_to_ident("val");
4371-
let val_pat = self.pat_ident(pat.span, val_ident);
4372-
let val_expr = P(self.expr_ident(pat.span, val_ident, val_pat.id));
4373-
let next_expr = P(self.expr_ident(pat.span, next_ident, next_pat.id));
4361+
let (val_pat, val_pat_nid) = self.pat_ident(pat.span, val_ident);
4362+
let val_expr = P(self.expr_ident(pat.span, val_ident, val_pat_nid));
4363+
let next_expr = P(self.expr_ident(pat.span, next_ident, next_pat_nid));
43744364
let assign = P(self.expr(
43754365
pat.span,
43764366
hir::ExprKind::Assign(next_expr, val_expr),
@@ -4389,15 +4379,15 @@ impl<'a> LoweringContext<'a> {
43894379
};
43904380

43914381
// `mut iter`
4392-
let iter_pat = self.pat_ident_binding_mode(
4382+
let (iter_pat, iter_pat_nid) = self.pat_ident_binding_mode(
43934383
desugared_span,
43944384
iter,
43954385
hir::BindingAnnotation::Mutable
43964386
);
43974387

43984388
// `match ::std::iter::Iterator::next(&mut iter) { ... }`
43994389
let match_expr = {
4400-
let iter = P(self.expr_ident(head_sp, iter, iter_pat.id));
4390+
let iter = P(self.expr_ident(head_sp, iter, iter_pat_nid));
44014391
let ref_mut_iter = self.expr_mut_addr_of(head_sp, iter);
44024392
let next_path = &["iter", "Iterator", "next"];
44034393
let next_path = P(self.expr_std_path(head_sp, next_path, None, ThinVec::new()));
@@ -4421,7 +4411,7 @@ impl<'a> LoweringContext<'a> {
44214411
span: head_sp,
44224412
};
44234413

4424-
let next_expr = P(self.expr_ident(head_sp, next_ident, next_pat.id));
4414+
let next_expr = P(self.expr_ident(head_sp, next_ident, next_pat_nid));
44254415

44264416
// `let mut __next`
44274417
let next_let = self.stmt_let_pat(
@@ -4548,11 +4538,11 @@ impl<'a> LoweringContext<'a> {
45484538
// `Ok(val) => #[allow(unreachable_code)] val,`
45494539
let ok_arm = {
45504540
let val_ident = self.str_to_ident("val");
4551-
let val_pat = self.pat_ident(e.span, val_ident);
4541+
let (val_pat, val_pat_nid) = self.pat_ident(e.span, val_ident);
45524542
let val_expr = P(self.expr_ident_with_attrs(
45534543
e.span,
45544544
val_ident,
4555-
val_pat.id,
4545+
val_pat_nid,
45564546
ThinVec::from(attrs.clone()),
45574547
));
45584548
let ok_pat = self.pat_ok(e.span, val_pat);
@@ -4564,12 +4554,12 @@ impl<'a> LoweringContext<'a> {
45644554
// return Try::from_error(From::from(err)),`
45654555
let err_arm = {
45664556
let err_ident = self.str_to_ident("err");
4567-
let err_local = self.pat_ident(e.span, err_ident);
4557+
let (err_local, err_local_nid) = self.pat_ident(e.span, err_ident);
45684558
let from_expr = {
45694559
let path = &["convert", "From", "from"];
45704560
let from = P(self.expr_std_path(
45714561
e.span, path, None, ThinVec::new()));
4572-
let err_expr = self.expr_ident(e.span, err_ident, err_local.id);
4562+
let err_expr = self.expr_ident(e.span, err_ident, err_local_nid);
45734563

45744564
self.expr_call(e.span, from, hir_vec![err_expr])
45754565
};
@@ -4917,15 +4907,15 @@ impl<'a> LoweringContext<'a> {
49174907
ident: Ident,
49184908
ex: P<hir::Expr>,
49194909
) -> (hir::Stmt, NodeId) {
4920-
let pat = if mutbl {
4910+
let (pat, pat_nid) = if mutbl {
49214911
self.pat_ident_binding_mode(sp, ident, hir::BindingAnnotation::Mutable)
49224912
} else {
49234913
self.pat_ident(sp, ident)
49244914
};
4925-
let pat_id = pat.id;
4915+
49264916
(
49274917
self.stmt_let_pat(sp, Some(ex), pat, hir::LocalSource::Normal),
4928-
pat_id,
4918+
pat_nid,
49294919
)
49304920
}
49314921

@@ -4983,7 +4973,7 @@ impl<'a> LoweringContext<'a> {
49834973
self.pat(span, pt)
49844974
}
49854975

4986-
fn pat_ident(&mut self, span: Span, ident: Ident) -> P<hir::Pat> {
4976+
fn pat_ident(&mut self, span: Span, ident: Ident) -> (P<hir::Pat>, NodeId) {
49874977
self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::Unannotated)
49884978
}
49894979

@@ -4992,25 +4982,26 @@ impl<'a> LoweringContext<'a> {
49924982
span: Span,
49934983
ident: Ident,
49944984
bm: hir::BindingAnnotation,
4995-
) -> P<hir::Pat> {
4985+
) -> (P<hir::Pat>, NodeId) {
49964986
let LoweredNodeId { node_id, hir_id } = self.next_id();
49974987

4998-
P(hir::Pat {
4999-
id: node_id,
5000-
hir_id,
5001-
node: hir::PatKind::Binding(bm, node_id, hir_id, ident.with_span_pos(span), None),
5002-
span,
5003-
})
4988+
(
4989+
P(hir::Pat {
4990+
hir_id,
4991+
node: hir::PatKind::Binding(bm, node_id, hir_id, ident.with_span_pos(span), None),
4992+
span,
4993+
}),
4994+
node_id
4995+
)
50044996
}
50054997

50064998
fn pat_wild(&mut self, span: Span) -> P<hir::Pat> {
50074999
self.pat(span, hir::PatKind::Wild)
50085000
}
50095001

50105002
fn pat(&mut self, span: Span, pat: hir::PatKind) -> P<hir::Pat> {
5011-
let LoweredNodeId { node_id, hir_id } = self.next_id();
5003+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
50125004
P(hir::Pat {
5013-
id: node_id,
50145005
hir_id,
50155006
node: pat,
50165007
span,

src/librustc/hir/map/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
356356
fn visit_item(&mut self, i: &'hir Item) {
357357
debug!("visit_item: {:?}", i);
358358
debug_assert_eq!(i.hir_id.owner,
359-
self.definitions.opt_def_index(i.id).unwrap());
359+
self.definitions.opt_def_index(self.hir_to_node_id[&i.hir_id]).unwrap());
360360
self.with_dep_node_owner(i.hir_id.owner, i, |this| {
361361
this.insert(i.span, i.hir_id, Node::Item(i));
362362
this.with_parent(i.hir_id, |this| {

src/librustc/hir/map/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl<'hir> Map<'hir> {
319319

320320
match node {
321321
Node::Item(item) => {
322-
let def_id = || self.local_def_id(item.id);
322+
let def_id = || self.local_def_id_from_hir_id(item.hir_id);
323323

324324
match item.node {
325325
ItemKind::Static(_, m, _) => Some(Def::Static(def_id(), m == MutMutable)),
@@ -341,7 +341,7 @@ impl<'hir> Map<'hir> {
341341
}
342342
}
343343
Node::ForeignItem(item) => {
344-
let def_id = self.local_def_id(item.id);
344+
let def_id = self.local_def_id_from_hir_id(item.hir_id);
345345
match item.node {
346346
ForeignItemKind::Fn(..) => Some(Def::Fn(def_id)),
347347
ForeignItemKind::Static(_, m) => Some(Def::Static(def_id, m)),
@@ -366,11 +366,11 @@ impl<'hir> Map<'hir> {
366366
}
367367
}
368368
Node::Variant(variant) => {
369-
let def_id = self.local_def_id(variant.node.data.id());
369+
let def_id = self.local_def_id_from_hir_id(variant.node.data.hir_id());
370370
Some(Def::Variant(def_id))
371371
}
372372
Node::StructCtor(variant) => {
373-
let def_id = self.local_def_id(variant.id());
373+
let def_id = self.local_def_id_from_hir_id(variant.hir_id());
374374
Some(Def::StructCtor(def_id, def::CtorKind::from_hir(variant)))
375375
}
376376
Node::AnonConst(_) |
@@ -427,15 +427,15 @@ impl<'hir> Map<'hir> {
427427
}
428428

429429
pub fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem {
430-
self.read(id.node_id);
430+
self.read_by_hir_id(id.hir_id);
431431

432432
// N.B., intentionally bypass `self.forest.krate()` so that we
433433
// do not trigger a read of the whole krate here
434434
self.forest.krate.trait_item(id)
435435
}
436436

437437
pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem {
438-
self.read(id.node_id);
438+
self.read_by_hir_id(id.hir_id);
439439

440440
// N.B., intentionally bypass `self.forest.krate()` so that we
441441
// do not trigger a read of the whole krate here
@@ -618,11 +618,11 @@ impl<'hir> Map<'hir> {
618618
}
619619

620620
for id in &module.trait_items {
621-
visitor.visit_trait_item(self.expect_trait_item(id.node_id));
621+
visitor.visit_trait_item(self.expect_trait_item_by_hir_id(id.hir_id));
622622
}
623623

624624
for id in &module.impl_items {
625-
visitor.visit_impl_item(self.expect_impl_item(id.node_id));
625+
visitor.visit_impl_item(self.expect_impl_item_by_hir_id(id.hir_id));
626626
}
627627
}
628628

0 commit comments

Comments
 (0)