Skip to content

Commit c1d2d83

Browse files
committed
Auto merge of #58754 - ljedrz:I_hate_NodeIds, r=Zoxc
Remove NodeId from more HIR nodes The next iteration of HirIdification (#57578). Removes `NodeId` from: - [x] `Stmt` - [x] `Local` - [x] `Field` - [x] `AnonConst` - [x] `TraitItem` - [x] `ImplItem` - [x] `TypeBinding` - [x] `Arg` - [x] `TraitRef` - [x] `VisibilityKind` It will most probably break clippy again; I'd appreciate a **delegate** again if/when it is good to go so I can attach a clippy fix later. r? @Zoxc
2 parents 17add24 + 9cd1845 commit c1d2d83

Some content is hidden

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

45 files changed

+368
-429
lines changed

src/librustc/hir/intravisit.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,6 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref:
878878
pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem) {
879879
// N.B., deliberately force a compilation error if/when new fields are added.
880880
let ImplItem {
881-
id: _,
882881
hir_id: _,
883882
ident,
884883
ref vis,
@@ -1106,7 +1105,7 @@ pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) {
11061105
}
11071106

11081107
pub fn walk_vis<'v, V: Visitor<'v>>(visitor: &mut V, vis: &'v Visibility) {
1109-
if let VisibilityKind::Restricted { ref path, id: _, hir_id } = vis.node {
1108+
if let VisibilityKind::Restricted { ref path, hir_id } = vis.node {
11101109
visitor.visit_id(hir_id);
11111110
visitor.visit_path(path, hir_id)
11121111
}

src/librustc/hir/lowering.rs

+21-46
Original file line numberDiff line numberDiff line change
@@ -1151,10 +1151,9 @@ impl<'a> LoweringContext<'a> {
11511151

11521152
fn lower_ty_binding(&mut self, b: &TypeBinding,
11531153
itctx: ImplTraitContext<'_>) -> hir::TypeBinding {
1154-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(b.id);
1154+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(b.id);
11551155

11561156
hir::TypeBinding {
1157-
id: node_id,
11581157
hir_id,
11591158
ident: b.ident,
11601159
ty: self.lower_ty(&b.ty, itctx),
@@ -1982,14 +1981,13 @@ impl<'a> LoweringContext<'a> {
19821981
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
19831982
hir::Ty { node: hir::TyKind::Tup(tys), hir_id, span }
19841983
};
1985-
let LoweredNodeId { node_id, hir_id } = this.next_id();
1984+
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
19861985

19871986
(
19881987
hir::GenericArgs {
19891988
args: hir_vec![GenericArg::Type(mk_tup(this, inputs, span))],
19901989
bindings: hir_vec![
19911990
hir::TypeBinding {
1992-
id: node_id,
19931991
hir_id,
19941992
ident: Ident::from_str(FN_OUTPUT_NAME),
19951993
ty: output
@@ -2008,7 +2006,7 @@ impl<'a> LoweringContext<'a> {
20082006
}
20092007

20102008
fn lower_local(&mut self, l: &Local) -> (hir::Local, SmallVec<[hir::ItemId; 1]>) {
2011-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(l.id);
2009+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(l.id);
20122010
let mut ids = SmallVec::<[hir::ItemId; 1]>::new();
20132011
if self.sess.features_untracked().impl_trait_in_bindings {
20142012
if let Some(ref ty) = l.ty {
@@ -2018,7 +2016,6 @@ impl<'a> LoweringContext<'a> {
20182016
}
20192017
let parent_def_id = DefId::local(self.current_hir_id_owner.last().unwrap().0);
20202018
(hir::Local {
2021-
id: node_id,
20222019
hir_id,
20232020
ty: l.ty
20242021
.as_ref()
@@ -2045,9 +2042,8 @@ impl<'a> LoweringContext<'a> {
20452042
}
20462043

20472044
fn lower_arg(&mut self, arg: &Arg) -> hir::Arg {
2048-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(arg.id);
2045+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(arg.id);
20492046
hir::Arg {
2050-
id: node_id,
20512047
hir_id,
20522048
pat: self.lower_pat(&arg.pat),
20532049
}
@@ -2327,13 +2323,12 @@ impl<'a> LoweringContext<'a> {
23272323
};
23282324

23292325
// "<Output = T>"
2330-
let LoweredNodeId { node_id, hir_id } = this.next_id();
2326+
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
23312327
let future_params = P(hir::GenericArgs {
23322328
args: hir_vec![],
23332329
bindings: hir_vec![hir::TypeBinding {
23342330
ident: Ident::from_str(FN_OUTPUT_NAME),
23352331
ty: output_ty,
2336-
id: node_id,
23372332
hir_id,
23382333
span,
23392334
}],
@@ -2343,13 +2338,12 @@ impl<'a> LoweringContext<'a> {
23432338
let future_path =
23442339
this.std_path(span, &["future", "Future"], Some(future_params), false);
23452340

2346-
let LoweredNodeId { node_id, hir_id } = this.next_id();
2341+
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
23472342
let mut bounds = vec![
23482343
hir::GenericBound::Trait(
23492344
hir::PolyTraitRef {
23502345
trait_ref: hir::TraitRef {
23512346
path: future_path,
2352-
ref_id: node_id,
23532347
hir_ref_id: hir_id,
23542348
},
23552349
bound_generic_params: hir_vec![],
@@ -2719,10 +2713,9 @@ impl<'a> LoweringContext<'a> {
27192713
hir::QPath::Resolved(None, path) => path.and_then(|path| path),
27202714
qpath => bug!("lower_trait_ref: unexpected QPath `{:?}`", qpath),
27212715
};
2722-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(p.ref_id);
2716+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(p.ref_id);
27232717
hir::TraitRef {
27242718
path,
2725-
ref_id: node_id,
27262719
hir_ref_id: hir_id,
27272720
}
27282721
}
@@ -2768,10 +2761,9 @@ impl<'a> LoweringContext<'a> {
27682761
}
27692762

27702763
fn lower_field(&mut self, f: &Field) -> hir::Field {
2771-
let LoweredNodeId { node_id, hir_id } = self.next_id();
2764+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
27722765

27732766
hir::Field {
2774-
id: node_id,
27752767
hir_id,
27762768
ident: f.ident,
27772769
expr: P(self.lower_expr(&f.expr)),
@@ -3123,12 +3115,11 @@ impl<'a> LoweringContext<'a> {
31233115
hir::VisibilityKind::Public => hir::VisibilityKind::Public,
31243116
hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
31253117
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
3126-
hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => {
3118+
hir::VisibilityKind::Restricted { ref path, hir_id: _ } => {
31273119
let id = this.next_id();
31283120
let path = this.renumber_segment_ids(path);
31293121
hir::VisibilityKind::Restricted {
31303122
path,
3131-
id: id.node_id,
31323123
hir_id: id.hir_id,
31333124
}
31343125
}
@@ -3230,12 +3221,11 @@ impl<'a> LoweringContext<'a> {
32303221
hir::VisibilityKind::Public => hir::VisibilityKind::Public,
32313222
hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar),
32323223
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
3233-
hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => {
3224+
hir::VisibilityKind::Restricted { ref path, hir_id: _ } => {
32343225
let id = this.next_id();
32353226
let path = this.renumber_segment_ids(path);
32363227
hir::VisibilityKind::Restricted {
32373228
path: path,
3238-
id: id.node_id,
32393229
hir_id: id.hir_id,
32403230
}
32413231
}
@@ -3353,7 +3343,6 @@ impl<'a> LoweringContext<'a> {
33533343
};
33543344

33553345
hir::TraitItem {
3356-
id: node_id,
33573346
hir_id,
33583347
ident: i.ident,
33593348
attrs: self.lower_attrs(&i.attrs),
@@ -3429,7 +3418,6 @@ impl<'a> LoweringContext<'a> {
34293418
};
34303419

34313420
hir::ImplItem {
3432-
id: node_id,
34333421
hir_id,
34343422
ident: i.ident,
34353423
attrs: self.lower_attrs(&i.attrs),
@@ -3813,9 +3801,8 @@ impl<'a> LoweringContext<'a> {
38133801

38143802
fn lower_anon_const(&mut self, c: &AnonConst) -> hir::AnonConst {
38153803
self.with_new_scopes(|this| {
3816-
let LoweredNodeId { node_id, hir_id } = this.lower_node_id(c.id);
3804+
let LoweredNodeId { node_id: _, hir_id } = this.lower_node_id(c.id);
38173805
hir::AnonConst {
3818-
id: node_id,
38193806
hir_id,
38203807
body: this.lower_body(None, |this| this.lower_expr(&c.value)),
38213808
}
@@ -4427,9 +4414,8 @@ impl<'a> LoweringContext<'a> {
44274414
ThinVec::new(),
44284415
))
44294416
};
4430-
let LoweredNodeId { node_id, hir_id } = self.next_id();
4417+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
44314418
let match_stmt = hir::Stmt {
4432-
id: node_id,
44334419
hir_id,
44344420
node: hir::StmtKind::Expr(match_expr),
44354421
span: head_sp,
@@ -4456,9 +4442,8 @@ impl<'a> LoweringContext<'a> {
44564442

44574443
let body_block = self.with_loop_scope(e.id, |this| this.lower_block(body, false));
44584444
let body_expr = P(self.expr_block(body_block, ThinVec::new()));
4459-
let LoweredNodeId { node_id, hir_id } = self.next_id();
4445+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
44604446
let body_stmt = hir::Stmt {
4461-
id: node_id,
44624447
hir_id,
44634448
node: hir::StmtKind::Expr(body_expr),
44644449
span: body.span,
@@ -4639,21 +4624,19 @@ impl<'a> LoweringContext<'a> {
46394624
let mut ids: SmallVec<[hir::Stmt; 1]> = item_ids
46404625
.into_iter()
46414626
.map(|item_id| {
4642-
let LoweredNodeId { node_id, hir_id } = self.next_id();
4627+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
46434628

46444629
hir::Stmt {
4645-
id: node_id,
46464630
hir_id,
46474631
node: hir::StmtKind::Item(item_id),
46484632
span: s.span,
46494633
}
46504634
})
46514635
.collect();
46524636
ids.push({
4653-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(s.id);
4637+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(s.id);
46544638

46554639
hir::Stmt {
4656-
id: node_id,
46574640
hir_id,
46584641
node: hir::StmtKind::Local(P(l)),
46594642
span: s.span,
@@ -4667,12 +4650,11 @@ impl<'a> LoweringContext<'a> {
46674650
return self.lower_item_id(it)
46684651
.into_iter()
46694652
.map(|item_id| {
4670-
let LoweredNodeId { node_id, hir_id } = id.take()
4653+
let LoweredNodeId { node_id: _, hir_id } = id.take()
46714654
.map(|id| self.lower_node_id(id))
46724655
.unwrap_or_else(|| self.next_id());
46734656

46744657
hir::Stmt {
4675-
id: node_id,
46764658
hir_id,
46774659
node: hir::StmtKind::Item(item_id),
46784660
span: s.span,
@@ -4681,20 +4663,18 @@ impl<'a> LoweringContext<'a> {
46814663
.collect();
46824664
}
46834665
StmtKind::Expr(ref e) => {
4684-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(s.id);
4666+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(s.id);
46854667

46864668
hir::Stmt {
4687-
id: node_id,
46884669
hir_id,
46894670
node: hir::StmtKind::Expr(P(self.lower_expr(e))),
46904671
span: s.span,
46914672
}
46924673
},
46934674
StmtKind::Semi(ref e) => {
4694-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(s.id);
4675+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(s.id);
46954676

46964677
hir::Stmt {
4697-
id: node_id,
46984678
hir_id,
46994679
node: hir::StmtKind::Semi(P(self.lower_expr(e))),
47004680
span: s.span,
@@ -4739,7 +4719,6 @@ impl<'a> LoweringContext<'a> {
47394719
ParamMode::Explicit,
47404720
explicit_owner,
47414721
)),
4742-
id: lowered_id.node_id,
47434722
hir_id: lowered_id.hir_id,
47444723
}
47454724
},
@@ -4809,10 +4788,9 @@ impl<'a> LoweringContext<'a> {
48094788
}
48104789

48114790
fn field(&mut self, ident: Ident, expr: P<hir::Expr>, span: Span) -> hir::Field {
4812-
let LoweredNodeId { node_id, hir_id } = self.next_id();
4791+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
48134792

48144793
hir::Field {
4815-
id: node_id,
48164794
hir_id,
48174795
ident,
48184796
span,
@@ -4912,22 +4890,20 @@ impl<'a> LoweringContext<'a> {
49124890
pat: P<hir::Pat>,
49134891
source: hir::LocalSource,
49144892
) -> hir::Stmt {
4915-
let LoweredNodeId { node_id, hir_id } = self.next_id();
4893+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
49164894

49174895
let local = hir::Local {
49184896
pat,
49194897
ty: None,
49204898
init: ex,
4921-
id: node_id,
49224899
hir_id,
49234900
span: sp,
49244901
attrs: ThinVec::new(),
49254902
source,
49264903
};
49274904

4928-
let LoweredNodeId { node_id, hir_id } = self.next_id();
4905+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
49294906
hir::Stmt {
4930-
id: node_id,
49314907
hir_id,
49324908
node: hir::StmtKind::Local(P(local)),
49334909
span: sp
@@ -5075,7 +5051,6 @@ impl<'a> LoweringContext<'a> {
50755051
bound_generic_params: hir::HirVec::new(),
50765052
trait_ref: hir::TraitRef {
50775053
path: path.and_then(|path| path),
5078-
ref_id: id.node_id,
50795054
hir_ref_id: id.hir_id,
50805055
},
50815056
span,

src/librustc/hir/map/collector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
386386

387387
fn visit_trait_item(&mut self, ti: &'hir TraitItem) {
388388
debug_assert_eq!(ti.hir_id.owner,
389-
self.definitions.opt_def_index(ti.id).unwrap());
389+
self.definitions.opt_def_index(self.hir_to_node_id[&ti.hir_id]).unwrap());
390390
self.with_dep_node_owner(ti.hir_id.owner, ti, |this| {
391391
this.insert(ti.span, ti.hir_id, Node::TraitItem(ti));
392392

@@ -398,7 +398,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
398398

399399
fn visit_impl_item(&mut self, ii: &'hir ImplItem) {
400400
debug_assert_eq!(ii.hir_id.owner,
401-
self.definitions.opt_def_index(ii.id).unwrap());
401+
self.definitions.opt_def_index(self.hir_to_node_id[&ii.hir_id]).unwrap());
402402
self.with_dep_node_owner(ii.hir_id.owner, ii, |this| {
403403
this.insert(ii.span, ii.hir_id, Node::ImplItem(ii));
404404

src/librustc/hir/map/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,15 @@ impl<'hir> Map<'hir> {
349349
}
350350
}
351351
Node::TraitItem(item) => {
352-
let def_id = self.local_def_id(item.id);
352+
let def_id = self.local_def_id_from_hir_id(item.hir_id);
353353
match item.node {
354354
TraitItemKind::Const(..) => Some(Def::AssociatedConst(def_id)),
355355
TraitItemKind::Method(..) => Some(Def::Method(def_id)),
356356
TraitItemKind::Type(..) => Some(Def::AssociatedTy(def_id)),
357357
}
358358
}
359359
Node::ImplItem(item) => {
360-
let def_id = self.local_def_id(item.id);
360+
let def_id = self.local_def_id_from_hir_id(item.hir_id);
361361
match item.node {
362362
ImplItemKind::Const(..) => Some(Def::AssociatedConst(def_id)),
363363
ImplItemKind::Method(..) => Some(Def::Method(def_id)),
@@ -387,7 +387,7 @@ impl<'hir> Map<'hir> {
387387
Node::Block(_) |
388388
Node::Crate => None,
389389
Node::Local(local) => {
390-
Some(Def::Local(local.id))
390+
Some(Def::Local(self.hir_to_node_id(local.hir_id)))
391391
}
392392
Node::MacroDef(macro_def) => {
393393
Some(Def::Macro(self.local_def_id_from_hir_id(macro_def.hir_id),

0 commit comments

Comments
 (0)