Simplify lower ast block
This commit is contained in:
parent
a4d9624242
commit
a808822093
@ -2409,26 +2409,12 @@ fn lower_block(&mut self, b: &Block, targeted_by_break: bool) -> &'hir hir::Bloc
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn lower_block_noalloc(&mut self, b: &Block, targeted_by_break: bool) -> hir::Block<'hir> {
|
fn lower_block_noalloc(&mut self, b: &Block, targeted_by_break: bool) -> hir::Block<'hir> {
|
||||||
let mut expr: Option<&'hir _> = None;
|
let (stmts, expr) = match &*b.stmts {
|
||||||
|
[stmts @ .., Stmt { kind: StmtKind::Expr(e), .. }] => (stmts, Some(&*e)),
|
||||||
let stmts = self.arena.alloc_from_iter(
|
stmts => (stmts, None),
|
||||||
b.stmts
|
};
|
||||||
.iter()
|
let stmts = self.arena.alloc_from_iter(stmts.iter().flat_map(|stmt| self.lower_stmt(stmt)));
|
||||||
.enumerate()
|
let expr = expr.map(|e| self.lower_expr(e));
|
||||||
.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 rules = self.lower_block_check_mode(&b.rules);
|
let rules = self.lower_block_check_mode(&b.rules);
|
||||||
let hir_id = self.lower_node_id(b.id);
|
let hir_id = self.lower_node_id(b.id);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user