Skip to content

Commit 001ef61

Browse files
committed
Work on removing HirId from hir::Stmt
1 parent 6d07d72 commit 001ef61

File tree

9 files changed

+22
-30
lines changed

9 files changed

+22
-30
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,49 +2415,41 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24152415
}
24162416

24172417
fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt<'hir>; 1]> {
2418-
let (hir_id, kind) = match s.kind {
2418+
let kind = match s.kind {
24192419
StmtKind::Local(ref l) => {
24202420
let l = self.lower_local(l);
24212421
let hir_id = self.lower_node_id(s.id());
24222422
self.alias_attrs(hir_id, l.hir_id);
24232423
return smallvec![hir::Stmt {
2424-
hir_id,
24252424
kind: hir::StmtKind::Local(self.arena.alloc(l)),
24262425
span: s.span,
24272426
}];
24282427
}
24292428
StmtKind::Item(ref it) => {
2430-
// Can only use the ID once.
2431-
let mut id = Some(s.id());
24322429
return self
24332430
.lower_item_id(it)
24342431
.into_iter()
24352432
.map(|item_id| {
2436-
let hir_id = id
2437-
.take()
2438-
.map(|id| self.lower_node_id(id))
2439-
.unwrap_or_else(|| self.next_id());
2440-
2441-
hir::Stmt { hir_id, kind: hir::StmtKind::Item(item_id), span: s.span }
2433+
hir::Stmt { kind: hir::StmtKind::Item(item_id), span: s.span }
24422434
})
24432435
.collect();
24442436
}
24452437
StmtKind::Expr(ref e) => {
24462438
let e = self.lower_expr(e);
24472439
let hir_id = self.lower_node_id(s.id());
24482440
self.alias_attrs(hir_id, e.hir_id);
2449-
(hir_id, hir::StmtKind::Expr(e))
2441+
hir::StmtKind::Expr(e)
24502442
}
24512443
StmtKind::Semi(ref e) => {
24522444
let e = self.lower_expr(e);
24532445
let hir_id = self.lower_node_id(s.id());
24542446
self.alias_attrs(hir_id, e.hir_id);
2455-
(hir_id, hir::StmtKind::Semi(e))
2447+
hir::StmtKind::Semi(e)
24562448
}
24572449
StmtKind::Empty { id: _ } => return smallvec![],
24582450
StmtKind::MacCall(..) => panic!("shouldn't exist here"),
24592451
};
2460-
smallvec![hir::Stmt { hir_id, kind, span: s.span }]
2452+
smallvec![hir::Stmt { kind, span: s.span }]
24612453
}
24622454

24632455
fn lower_block_check_mode(&mut self, b: &BlockCheckMode) -> hir::BlockCheckMode {
@@ -2492,7 +2484,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24922484
// Helper methods for building HIR.
24932485

24942486
fn stmt(&mut self, span: Span, kind: hir::StmtKind<'hir>) -> hir::Stmt<'hir> {
2495-
hir::Stmt { span, kind, hir_id: self.next_id() }
2487+
hir::Stmt { span, kind }
24962488
}
24972489

24982490
fn stmt_expr(&mut self, span: Span, expr: hir::Expr<'hir>) -> hir::Stmt<'hir> {

compiler/rustc_hir/src/hir.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,6 @@ impl UnOp {
11621162
/// A statement.
11631163
#[derive(Debug, HashStable_Generic)]
11641164
pub struct Stmt<'hir> {
1165-
pub hir_id: HirId,
11661165
pub kind: StmtKind<'hir>,
11671166
pub span: Span,
11681167
}
@@ -1183,6 +1182,16 @@ pub enum StmtKind<'hir> {
11831182
Semi(&'hir Expr<'hir>),
11841183
}
11851184

1185+
impl<'hir> StmtKind<'hir> {
1186+
pub fn hir_id(&self) -> HirId {
1187+
match self {
1188+
StmtKind::Local(local) => local.hir_id,
1189+
StmtKind::Item(id) => id.hir_id(),
1190+
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.hir_id,
1191+
}
1192+
}
1193+
}
1194+
11861195
/// Represents a `let` statement (i.e., `let <pat>:<ty> = <expr>;`).
11871196
#[derive(Debug, HashStable_Generic)]
11881197
pub struct Local<'hir> {
@@ -3233,7 +3242,6 @@ impl<'hir> Node<'hir> {
32333242
Node::Field(FieldDef { hir_id, .. })
32343243
| Node::AnonConst(AnonConst { hir_id, .. })
32353244
| Node::Expr(Expr { hir_id, .. })
3236-
| Node::Stmt(Stmt { hir_id, .. })
32373245
| Node::Ty(Ty { hir_id, .. })
32383246
| Node::Binding(Pat { hir_id, .. })
32393247
| Node::Pat(Pat { hir_id, .. })
@@ -3244,6 +3252,7 @@ impl<'hir> Node<'hir> {
32443252
| Node::Param(Param { hir_id, .. })
32453253
| Node::Infer(InferArg { hir_id, .. })
32463254
| Node::GenericParam(GenericParam { hir_id, .. }) => Some(*hir_id),
3255+
Node::Stmt(stmt) => Some(stmt.kind.hir_id()),
32473256
Node::TraitRef(TraitRef { hir_ref_id, .. }) => Some(*hir_ref_id),
32483257
Node::PathSegment(PathSegment { hir_id, .. }) => *hir_id,
32493258
Node::Variant(Variant { id, .. }) => Some(*id),

compiler/rustc_hir/src/intravisit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,6 @@ pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block<'v>) {
11021102
}
11031103

11041104
pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt<'v>) {
1105-
visitor.visit_id(statement.hir_id);
11061105
match statement.kind {
11071106
StmtKind::Local(ref local) => visitor.visit_local(local),
11081107
StmtKind::Item(item) => visitor.visit_nested_item(item),

compiler/rustc_lint/src/late.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
180180
fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) {
181181
// See `EarlyContextAndPass::visit_stmt` for an explanation
182182
// of why we call `walk_stmt` outside of `with_lint_attrs`
183-
self.with_lint_attrs(s.hir_id, |cx| {
183+
self.with_lint_attrs(s.kind.hir_id(), |cx| {
184184
lint_callback!(cx, check_stmt, s);
185185
});
186186
hir_visit::walk_stmt(self, s);

compiler/rustc_middle/src/hir/map/collector.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,6 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
313313
});
314314
}
315315

316-
fn visit_stmt(&mut self, stmt: &'hir Stmt<'hir>) {
317-
self.insert(stmt.span, stmt.hir_id, Node::Stmt(stmt));
318-
319-
self.with_parent(stmt.hir_id, |this| {
320-
intravisit::walk_stmt(this, stmt);
321-
});
322-
}
323-
324316
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'hir PathSegment<'hir>) {
325317
if let Some(hir_id) = path_segment.hir_id {
326318
self.insert(path_span, hir_id, Node::PathSegment(path_segment));

compiler/rustc_mir_build/src/thir/cx/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'tcx> Cx<'tcx> {
4545
.iter()
4646
.enumerate()
4747
.filter_map(|(index, stmt)| {
48-
let hir_id = stmt.hir_id;
48+
let hir_id = stmt.kind.hir_id();
4949
let opt_dxn_ext = self.region_scope_tree.opt_destruction_scope(hir_id.local_id);
5050
match stmt.kind {
5151
hir::StmtKind::Expr(ref expr) | hir::StmtKind::Semi(ref expr) => {

compiler/rustc_passes/src/hir_stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
145145
}
146146

147147
fn visit_stmt(&mut self, s: &'v hir::Stmt<'v>) {
148-
self.record("Stmt", Id::Node(s.hir_id), s);
148+
self.record("Stmt", Id::Node(s.kind.hir_id()), s);
149149
hir_visit::walk_stmt(self, s)
150150
}
151151

compiler/rustc_passes/src/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ fn resolve_pat<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, pat: &'tcx hir
185185
}
186186

187187
fn resolve_stmt<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, stmt: &'tcx hir::Stmt<'tcx>) {
188-
let stmt_id = stmt.hir_id.local_id;
188+
let stmt_id = stmt.kind.hir_id().local_id;
189189
debug!("resolve_stmt(stmt.id={:?})", stmt_id);
190190

191191
// Every statement will clean up the temporaries created during

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
567567
hir::StmtKind::Local(..) | hir::StmtKind::Expr(..) | hir::StmtKind::Semi(..) => {}
568568
}
569569

570-
self.warn_if_unreachable(stmt.hir_id, stmt.span, "statement");
570+
self.warn_if_unreachable(stmt.kind.hir_id(), stmt.span, "statement");
571571

572572
// Hide the outer diverging and `has_errors` flags.
573573
let old_diverges = self.diverges.replace(Diverges::Maybe);

0 commit comments

Comments
 (0)