introduce lower_block_expr
convenience function, and use it
This commit is contained in:
parent
123f129f79
commit
0a11e80fa8
3 changed files with 12 additions and 14 deletions
|
@ -2708,6 +2708,13 @@ impl<'a> LoweringContext<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
/// Lowers a block directly to an expression, presuming that it
|
||||
/// has no attributes and is not targeted by a `break`.
|
||||
fn lower_block_expr(&mut self, b: &Block) -> hir::Expr {
|
||||
let block = self.lower_block(b, false);
|
||||
self.expr_block(block, ThinVec::new())
|
||||
}
|
||||
|
||||
fn lower_pat(&mut self, p: &Pat) -> P<hir::Pat> {
|
||||
let node = match p.node {
|
||||
PatKind::Wild => hir::PatKind::Wild,
|
||||
|
|
|
@ -90,10 +90,7 @@ impl LoweringContext<'_> {
|
|||
),
|
||||
ExprKind::Async(capture_clause, closure_node_id, ref block) => {
|
||||
self.make_async_expr(capture_clause, closure_node_id, None, block.span, |this| {
|
||||
this.with_new_scopes(|this| {
|
||||
let block = this.lower_block(block, false);
|
||||
this.expr_block(block, ThinVec::new())
|
||||
})
|
||||
this.with_new_scopes(|this| this.lower_block_expr(block))
|
||||
})
|
||||
}
|
||||
ExprKind::Await(ref expr) => self.lower_expr_await(e.span, expr),
|
||||
|
@ -284,8 +281,7 @@ impl LoweringContext<'_> {
|
|||
let else_arm = self.arm(hir_vec![else_pat], P(else_expr));
|
||||
|
||||
// Handle then + scrutinee:
|
||||
let then_blk = self.lower_block(then, false);
|
||||
let then_expr = self.expr_block(then_blk, ThinVec::new());
|
||||
let then_expr = self.lower_block_expr(then);
|
||||
let (then_pat, scrutinee, desugar) = match cond.node {
|
||||
// `<pat> => <then>`:
|
||||
ExprKind::Let(ref pat, ref scrutinee) => {
|
||||
|
@ -335,8 +331,7 @@ impl LoweringContext<'_> {
|
|||
};
|
||||
|
||||
// Handle then + scrutinee:
|
||||
let then_blk = self.lower_block(body, false);
|
||||
let then_expr = self.expr_block(then_blk, ThinVec::new());
|
||||
let then_expr = self.lower_block_expr(body);
|
||||
let (then_pat, scrutinee, desugar, source) = match cond.node {
|
||||
ExprKind::Let(ref pat, ref scrutinee) => {
|
||||
// to:
|
||||
|
|
|
@ -1071,10 +1071,7 @@ impl LoweringContext<'_> {
|
|||
}
|
||||
|
||||
fn lower_fn_body_block(&mut self, decl: &FnDecl, body: &Block) -> hir::BodyId {
|
||||
self.lower_fn_body(decl, |this| {
|
||||
let body = this.lower_block(body, false);
|
||||
this.expr_block(body, ThinVec::new())
|
||||
})
|
||||
self.lower_fn_body(decl, |this| this.lower_block_expr(body))
|
||||
}
|
||||
|
||||
pub(super) fn lower_const_body(&mut self, expr: &Expr) -> hir::BodyId {
|
||||
|
@ -1220,8 +1217,7 @@ impl LoweringContext<'_> {
|
|||
CaptureBy::Value, closure_id, None, body.span,
|
||||
|this| {
|
||||
// Create a block from the user's function body:
|
||||
let user_body = this.lower_block(body, false);
|
||||
let user_body = this.expr_block(user_body, ThinVec::new());
|
||||
let user_body = this.lower_block_expr(body);
|
||||
|
||||
// Transform into `drop-temps { <user-body> }`, an expression:
|
||||
let desugared_span = this.mark_span_with_reason(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue