Skip to content

Commit ea43c3c

Browse files
committed
Auto merge of #58561 - ljedrz:HirIdify_some_nodes, r=Zoxc
Remove NodeId from some HIR nodes The next iteration of #57578. Removes `NodeId` from: - [x] `Lifetime` - [x] `Ty` - [x] `GenericParam` - [x] `WhereClause` - [x] `WhereEqPredicate` - [x] `MacroDef` - [x] `Block` - [x] `Expr` r? @Zoxc
2 parents fb162e6 + 77a30ec commit ea43c3c

Some content is hidden

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

70 files changed

+642
-673
lines changed

src/librustc/cfg/construct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
398398
args: I) -> CFGIndex {
399399
let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
400400
let ret = self.straightline(call_expr, func_or_rcvr_exit, args);
401-
let m = self.tcx.hir().get_module_parent(call_expr.id);
401+
let m = self.tcx.hir().get_module_parent_by_hir_id(call_expr.hir_id);
402402
if self.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(call_expr)) {
403403
self.add_unreachable_node()
404404
} else {

src/librustc/hir/lowering.rs

+23-48
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ impl<'a> LoweringContext<'a> {
780780
);
781781

782782
hir::GenericParam {
783-
id: node_id,
784783
hir_id,
785784
name: hir_name,
786785
attrs: hir_vec![],
@@ -964,7 +963,6 @@ impl<'a> LoweringContext<'a> {
964963
let closure_hir_id = self.lower_node_id(closure_node_id).hir_id;
965964
let decl = self.lower_fn_decl(&decl, None, /* impl trait allowed */ false, None);
966965
let generator = hir::Expr {
967-
id: closure_node_id,
968966
hir_id: closure_hir_id,
969967
node: hir::ExprKind::Closure(capture_clause, decl, body_id, span,
970968
Some(hir::GeneratorMovability::Static)),
@@ -1300,7 +1298,6 @@ impl<'a> LoweringContext<'a> {
13001298
// Set the name to `impl Bound1 + Bound2`.
13011299
let ident = Ident::from_str(&pprust::ty_to_string(t)).with_span_pos(span);
13021300
in_band_ty_params.push(hir::GenericParam {
1303-
id: def_node_id,
13041301
hir_id,
13051302
name: ParamName::Plain(ident),
13061303
pure_wrt_drop: false,
@@ -1350,9 +1347,8 @@ impl<'a> LoweringContext<'a> {
13501347
TyKind::Mac(_) => panic!("TyMac should have been expanded by now."),
13511348
};
13521349

1353-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(t.id);
1350+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(t.id);
13541351
hir::Ty {
1355-
id: node_id,
13561352
node: kind,
13571353
span: t.span,
13581354
hir_id,
@@ -1394,12 +1390,11 @@ impl<'a> LoweringContext<'a> {
13941390
);
13951391

13961392
self.with_hir_id_owner(exist_ty_node_id, |lctx| {
1397-
let LoweredNodeId { node_id, hir_id } = lctx.next_id();
1393+
let LoweredNodeId { node_id: _, hir_id } = lctx.next_id();
13981394
let exist_ty_item_kind = hir::ItemKind::Existential(hir::ExistTy {
13991395
generics: hir::Generics {
14001396
params: lifetime_defs,
14011397
where_clause: hir::WhereClause {
1402-
id: node_id,
14031398
hir_id,
14041399
predicates: Vec::new().into(),
14051400
},
@@ -1533,9 +1528,8 @@ impl<'a> LoweringContext<'a> {
15331528
&& !self.already_defined_lifetimes.contains(&name) {
15341529
self.already_defined_lifetimes.insert(name);
15351530

1536-
let LoweredNodeId { node_id, hir_id } = self.context.next_id();
1531+
let LoweredNodeId { node_id: _, hir_id } = self.context.next_id();
15371532
self.output_lifetimes.push(hir::GenericArg::Lifetime(hir::Lifetime {
1538-
id: node_id,
15391533
hir_id,
15401534
span: lifetime.span,
15411535
name,
@@ -1569,7 +1563,6 @@ impl<'a> LoweringContext<'a> {
15691563
};
15701564

15711565
self.output_lifetime_params.push(hir::GenericParam {
1572-
id: def_node_id,
15731566
hir_id,
15741567
name,
15751568
span: lifetime.span,
@@ -1980,8 +1973,8 @@ impl<'a> LoweringContext<'a> {
19801973
.map(|ty| this.lower_ty_direct(ty, ImplTraitContext::disallowed()))
19811974
.collect();
19821975
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 }
1976+
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
1977+
hir::Ty { node: hir::TyKind::Tup(tys), hir_id, span }
19851978
};
19861979
let LoweredNodeId { node_id, hir_id } = this.next_id();
19871980

@@ -2318,9 +2311,8 @@ impl<'a> LoweringContext<'a> {
23182311
this.lower_ty(ty, ImplTraitContext::Existential(Some(fn_def_id)))
23192312
}
23202313
FunctionRetTy::Default(span) => {
2321-
let LoweredNodeId { node_id, hir_id } = this.next_id();
2314+
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
23222315
P(hir::Ty {
2323-
id: node_id,
23242316
hir_id,
23252317
node: hir::TyKind::Tup(hir_vec![]),
23262318
span: *span,
@@ -2362,17 +2354,16 @@ impl<'a> LoweringContext<'a> {
23622354
];
23632355

23642356
if let Some((name, span)) = bound_lifetime {
2365-
let LoweredNodeId { node_id, hir_id } = this.next_id();
2357+
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
23662358
bounds.push(hir::GenericBound::Outlives(
2367-
hir::Lifetime { id: node_id, hir_id, name, span }));
2359+
hir::Lifetime { hir_id, name, span }));
23682360
}
23692361

23702362
hir::HirVec::from(bounds)
23712363
});
23722364

2373-
let LoweredNodeId { node_id, hir_id } = self.next_id();
2365+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
23742366
let impl_trait_ty = P(hir::Ty {
2375-
id: node_id,
23762367
node: impl_trait_ty,
23772368
span,
23782369
hir_id,
@@ -2431,10 +2422,9 @@ impl<'a> LoweringContext<'a> {
24312422
span: Span,
24322423
name: hir::LifetimeName,
24332424
) -> hir::Lifetime {
2434-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id);
2425+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id);
24352426

24362427
hir::Lifetime {
2437-
id: node_id,
24382428
hir_id,
24392429
span,
24402430
name: name,
@@ -2524,10 +2514,9 @@ impl<'a> LoweringContext<'a> {
25242514
}
25252515
};
25262516

2527-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(param.id);
2517+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(param.id);
25282518

25292519
hir::GenericParam {
2530-
id: node_id,
25312520
hir_id,
25322521
name,
25332522
span: param.ident.span,
@@ -2608,10 +2597,9 @@ impl<'a> LoweringContext<'a> {
26082597
self.with_anonymous_lifetime_mode(
26092598
AnonymousLifetimeMode::ReportError,
26102599
|this| {
2611-
let LoweredNodeId { node_id, hir_id } = this.lower_node_id(wc.id);
2600+
let LoweredNodeId { node_id: _, hir_id } = this.lower_node_id(wc.id);
26122601

26132602
hir::WhereClause {
2614-
id: node_id,
26152603
hir_id,
26162604
predicates: wc.predicates
26172605
.iter()
@@ -2672,10 +2660,9 @@ impl<'a> LoweringContext<'a> {
26722660
ref rhs_ty,
26732661
span,
26742662
}) => {
2675-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id);
2663+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id);
26762664

26772665
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
2678-
id: node_id,
26792666
hir_id,
26802667
lhs_ty: self.lower_ty(lhs_ty, ImplTraitContext::disallowed()),
26812668
rhs_ty: self.lower_ty(rhs_ty, ImplTraitContext::disallowed()),
@@ -2816,10 +2803,9 @@ impl<'a> LoweringContext<'a> {
28162803
}
28172804
}
28182805

2819-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(b.id);
2806+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(b.id);
28202807

28212808
P(hir::Block {
2822-
id: node_id,
28232809
hir_id,
28242810
stmts: stmts.into(),
28252811
expr,
@@ -3544,7 +3530,6 @@ impl<'a> LoweringContext<'a> {
35443530
name: ident.name,
35453531
vis,
35463532
attrs,
3547-
id: i.id,
35483533
hir_id,
35493534
span: i.span,
35503535
body,
@@ -3900,11 +3885,10 @@ impl<'a> LoweringContext<'a> {
39003885
// Wrap the `if let` expr in a block.
39013886
let span = els.span;
39023887
let els = P(self.lower_expr(els));
3903-
let LoweredNodeId { node_id, hir_id } = self.next_id();
3888+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
39043889
let blk = P(hir::Block {
39053890
stmts: hir_vec![],
39063891
expr: Some(els),
3907-
id: node_id,
39083892
hir_id,
39093893
rules: hir::DefaultBlock,
39103894
span,
@@ -3947,10 +3931,9 @@ impl<'a> LoweringContext<'a> {
39473931
let mut block = this.lower_block(body, true).into_inner();
39483932
let tail = block.expr.take().map_or_else(
39493933
|| {
3950-
let LoweredNodeId { node_id, hir_id } = this.next_id();
3934+
let LoweredNodeId { node_id: _, hir_id } = this.next_id();
39513935
let span = this.sess.source_map().end_point(unstable_span);
39523936
hir::Expr {
3953-
id: node_id,
39543937
span,
39553938
node: hir::ExprKind::Tup(hir_vec![]),
39563939
attrs: ThinVec::new(),
@@ -4135,10 +4118,9 @@ impl<'a> LoweringContext<'a> {
41354118
let struct_path = self.std_path(e.span, &struct_path, None, is_unit);
41364119
let struct_path = hir::QPath::Resolved(None, P(struct_path));
41374120

4138-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id);
4121+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(e.id);
41394122

41404123
return hir::Expr {
4141-
id: node_id,
41424124
hir_id,
41434125
node: if is_unit {
41444126
hir::ExprKind::Path(struct_path)
@@ -4488,9 +4470,8 @@ impl<'a> LoweringContext<'a> {
44884470
self.lower_label(opt_label),
44894471
hir::LoopSource::ForLoop,
44904472
);
4491-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id);
4473+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(e.id);
44924474
let loop_expr = P(hir::Expr {
4493-
id: node_id,
44944475
hir_id,
44954476
node: loop_expr,
44964477
span: e.span,
@@ -4635,10 +4616,9 @@ impl<'a> LoweringContext<'a> {
46354616
ExprKind::Mac(_) => panic!("Shouldn't exist here"),
46364617
};
46374618

4638-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id);
4619+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(e.id);
46394620

46404621
hir::Expr {
4641-
id: node_id,
46424622
hir_id,
46434623
node: kind,
46444624
span: e.span,
@@ -4910,9 +4890,8 @@ impl<'a> LoweringContext<'a> {
49104890
}
49114891

49124892
fn expr(&mut self, span: Span, node: hir::ExprKind, attrs: ThinVec<Attribute>) -> hir::Expr {
4913-
let LoweredNodeId { node_id, hir_id } = self.next_id();
4893+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
49144894
hir::Expr {
4915-
id: node_id,
49164895
hir_id,
49174896
node,
49184897
span,
@@ -4978,12 +4957,11 @@ impl<'a> LoweringContext<'a> {
49784957
stmts: hir::HirVec<hir::Stmt>,
49794958
expr: Option<P<hir::Expr>>,
49804959
) -> hir::Block {
4981-
let LoweredNodeId { node_id, hir_id } = self.next_id();
4960+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
49824961

49834962
hir::Block {
49844963
stmts,
49854964
expr,
4986-
id: node_id,
49874965
hir_id,
49884966
rules: hir::DefaultBlock,
49894967
span,
@@ -5108,7 +5086,6 @@ impl<'a> LoweringContext<'a> {
51085086
_ => hir::TyKind::Path(qpath),
51095087
};
51105088
hir::Ty {
5111-
id: id.node_id,
51125089
hir_id: id.hir_id,
51135090
node,
51145091
span,
@@ -5124,9 +5101,8 @@ impl<'a> LoweringContext<'a> {
51245101
// `'f`.
51255102
AnonymousLifetimeMode::CreateParameter => {
51265103
let fresh_name = self.collect_fresh_in_band_lifetime(span);
5127-
let LoweredNodeId { node_id, hir_id } = self.next_id();
5104+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
51285105
hir::Lifetime {
5129-
id: node_id,
51305106
hir_id,
51315107
span,
51325108
name: hir::LifetimeName::Param(fresh_name),
@@ -5227,10 +5203,9 @@ impl<'a> LoweringContext<'a> {
52275203
}
52285204

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

52325208
hir::Lifetime {
5233-
id: node_id,
52345209
hir_id,
52355210
span,
52365211
name: hir::LifetimeName::Implicit,

src/librustc/hir/map/blocks.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ pub enum Code<'a> {
7575
}
7676

7777
impl<'a> Code<'a> {
78-
pub fn id(&self) -> NodeId {
78+
pub fn id(&self) -> ast::HirId {
7979
match *self {
8080
Code::FnLike(node) => node.id(),
81-
Code::Expr(block) => block.id,
81+
Code::Expr(block) => block.hir_id,
8282
}
8383
}
8484

@@ -104,7 +104,7 @@ struct ItemFnParts<'a> {
104104
vis: &'a ast::Visibility,
105105
generics: &'a ast::Generics,
106106
body: ast::BodyId,
107-
id: NodeId,
107+
id: ast::HirId,
108108
span: Span,
109109
attrs: &'a [Attribute],
110110
}
@@ -114,13 +114,13 @@ struct ItemFnParts<'a> {
114114
struct ClosureParts<'a> {
115115
decl: &'a FnDecl,
116116
body: ast::BodyId,
117-
id: NodeId,
117+
id: ast::HirId,
118118
span: Span,
119119
attrs: &'a [Attribute],
120120
}
121121

122122
impl<'a> ClosureParts<'a> {
123-
fn new(d: &'a FnDecl, b: ast::BodyId, id: NodeId, s: Span, attrs: &'a [Attribute]) -> Self {
123+
fn new(d: &'a FnDecl, b: ast::BodyId, id: ast::HirId, s: Span, attrs: &'a [Attribute]) -> Self {
124124
ClosureParts {
125125
decl: d,
126126
body: b,
@@ -168,7 +168,7 @@ impl<'a> FnLikeNode<'a> {
168168
|c: ClosureParts<'_>| c.span)
169169
}
170170

171-
pub fn id(self) -> NodeId {
171+
pub fn id(self) -> ast::HirId {
172172
self.handle(|i: ItemFnParts<'_>| i.id,
173173
|id, _, _: &'a ast::MethodSig, _, _, _, _| id,
174174
|c: ClosureParts<'_>| c.id)
@@ -213,7 +213,7 @@ impl<'a> FnLikeNode<'a> {
213213

214214
fn handle<A, I, M, C>(self, item_fn: I, method: M, closure: C) -> A where
215215
I: FnOnce(ItemFnParts<'a>) -> A,
216-
M: FnOnce(NodeId,
216+
M: FnOnce(ast::HirId,
217217
Ident,
218218
&'a ast::MethodSig,
219219
Option<&'a ast::Visibility>,
@@ -227,7 +227,7 @@ impl<'a> FnLikeNode<'a> {
227227
map::Node::Item(i) => match i.node {
228228
ast::ItemKind::Fn(ref decl, header, ref generics, block) =>
229229
item_fn(ItemFnParts {
230-
id: i.id,
230+
id: i.hir_id,
231231
ident: i.ident,
232232
decl: &decl,
233233
body: block,
@@ -241,21 +241,21 @@ impl<'a> FnLikeNode<'a> {
241241
},
242242
map::Node::TraitItem(ti) => match ti.node {
243243
ast::TraitItemKind::Method(ref sig, ast::TraitMethod::Provided(body)) => {
244-
method(ti.id, ti.ident, sig, None, body, ti.span, &ti.attrs)
244+
method(ti.hir_id, ti.ident, sig, None, body, ti.span, &ti.attrs)
245245
}
246246
_ => bug!("trait method FnLikeNode that is not fn-like"),
247247
},
248248
map::Node::ImplItem(ii) => {
249249
match ii.node {
250250
ast::ImplItemKind::Method(ref sig, body) => {
251-
method(ii.id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
251+
method(ii.hir_id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
252252
}
253253
_ => bug!("impl method FnLikeNode that is not fn-like")
254254
}
255255
},
256256
map::Node::Expr(e) => match e.node {
257257
ast::ExprKind::Closure(_, ref decl, block, _fn_decl_span, _gen) =>
258-
closure(ClosureParts::new(&decl, block, e.id, e.span, &e.attrs)),
258+
closure(ClosureParts::new(&decl, block, e.hir_id, e.span, &e.attrs)),
259259
_ => bug!("expr FnLikeNode that is not fn-like"),
260260
},
261261
_ => bug!("other FnLikeNode that is not fn-like"),

0 commit comments

Comments
 (0)