Skip to content

Commit 6a7953d

Browse files
authored
Rollup merge of #82984 - camsteffen:lower-block, r=cjgillot
Simplify ast block lowering
2 parents be17609 + a808822 commit 6a7953d

File tree

1 file changed

+6
-20
lines changed
  • compiler/rustc_ast_lowering/src

1 file changed

+6
-20
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,26 +2416,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24162416
}
24172417

24182418
fn lower_block_noalloc(&mut self, b: &Block, targeted_by_break: bool) -> hir::Block<'hir> {
2419-
let mut expr: Option<&'hir _> = None;
2420-
2421-
let stmts = self.arena.alloc_from_iter(
2422-
b.stmts
2423-
.iter()
2424-
.enumerate()
2425-
.filter_map(|(index, stmt)| {
2426-
if index == b.stmts.len() - 1 {
2427-
if let StmtKind::Expr(ref e) = stmt.kind {
2428-
expr = Some(self.lower_expr(e));
2429-
None
2430-
} else {
2431-
Some(self.lower_stmt(stmt))
2432-
}
2433-
} else {
2434-
Some(self.lower_stmt(stmt))
2435-
}
2436-
})
2437-
.flatten(),
2438-
);
2419+
let (stmts, expr) = match &*b.stmts {
2420+
[stmts @ .., Stmt { kind: StmtKind::Expr(e), .. }] => (stmts, Some(&*e)),
2421+
stmts => (stmts, None),
2422+
};
2423+
let stmts = self.arena.alloc_from_iter(stmts.iter().flat_map(|stmt| self.lower_stmt(stmt)));
2424+
let expr = expr.map(|e| self.lower_expr(e));
24392425
let rules = self.lower_block_check_mode(&b.rules);
24402426
let hir_id = self.lower_node_id(b.id);
24412427

0 commit comments

Comments
 (0)