Skip to content

Commit a808822

Browse files
committed
Simplify lower ast block
1 parent a4d9624 commit a808822

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

+6-20
Original file line numberDiff line numberDiff line change
@@ -2409,26 +2409,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24092409
}
24102410

24112411
fn lower_block_noalloc(&mut self, b: &Block, targeted_by_break: bool) -> hir::Block<'hir> {
2412-
let mut expr: Option<&'hir _> = None;
2413-
2414-
let stmts = self.arena.alloc_from_iter(
2415-
b.stmts
2416-
.iter()
2417-
.enumerate()
2418-
.filter_map(|(index, stmt)| {
2419-
if index == b.stmts.len() - 1 {
2420-
if let StmtKind::Expr(ref e) = stmt.kind {
2421-
expr = Some(self.lower_expr(e));
2422-
None
2423-
} else {
2424-
Some(self.lower_stmt(stmt))
2425-
}
2426-
} else {
2427-
Some(self.lower_stmt(stmt))
2428-
}
2429-
})
2430-
.flatten(),
2431-
);
2412+
let (stmts, expr) = match &*b.stmts {
2413+
[stmts @ .., Stmt { kind: StmtKind::Expr(e), .. }] => (stmts, Some(&*e)),
2414+
stmts => (stmts, None),
2415+
};
2416+
let stmts = self.arena.alloc_from_iter(stmts.iter().flat_map(|stmt| self.lower_stmt(stmt)));
2417+
let expr = expr.map(|e| self.lower_expr(e));
24322418
let rules = self.lower_block_check_mode(&b.rules);
24332419
let hir_id = self.lower_node_id(b.id);
24342420

0 commit comments

Comments
 (0)