Skip to content

Commit

Permalink
Rollup merge of #82984 - camsteffen:lower-block, r=cjgillot
Browse files Browse the repository at this point in the history
Simplify ast block lowering
  • Loading branch information
JohnTitor authored Mar 13, 2021
2 parents b3e19a2 + a808822 commit fa3f186
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2409,26 +2409,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}

fn lower_block_noalloc(&mut self, b: &Block, targeted_by_break: bool) -> hir::Block<'hir> {
let mut expr: Option<&'hir _> = None;

let stmts = self.arena.alloc_from_iter(
b.stmts
.iter()
.enumerate()
.filter_map(|(index, stmt)| {
if index == b.stmts.len() - 1 {
if let StmtKind::Expr(ref e) = stmt.kind {
expr = Some(self.lower_expr(e));
None
} else {
Some(self.lower_stmt(stmt))
}
} else {
Some(self.lower_stmt(stmt))
}
})
.flatten(),
);
let (stmts, expr) = match &*b.stmts {
[stmts @ .., Stmt { kind: StmtKind::Expr(e), .. }] => (stmts, Some(&*e)),
stmts => (stmts, None),
};
let stmts = self.arena.alloc_from_iter(stmts.iter().flat_map(|stmt| self.lower_stmt(stmt)));
let expr = expr.map(|e| self.lower_expr(e));
let rules = self.lower_block_check_mode(&b.rules);
let hir_id = self.lower_node_id(b.id);

Expand Down

0 comments on commit fa3f186

Please sign in to comment.