Skip to content

Commit 0a11e80

Browse files
committed
introduce lower_block_expr convenience function, and use it
1 parent 123f129 commit 0a11e80

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/librustc/hir/lowering.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,6 +2708,13 @@ impl<'a> LoweringContext<'a> {
27082708
})
27092709
}
27102710

2711+
/// Lowers a block directly to an expression, presuming that it
2712+
/// has no attributes and is not targeted by a `break`.
2713+
fn lower_block_expr(&mut self, b: &Block) -> hir::Expr {
2714+
let block = self.lower_block(b, false);
2715+
self.expr_block(block, ThinVec::new())
2716+
}
2717+
27112718
fn lower_pat(&mut self, p: &Pat) -> P<hir::Pat> {
27122719
let node = match p.node {
27132720
PatKind::Wild => hir::PatKind::Wild,

src/librustc/hir/lowering/expr.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ impl LoweringContext<'_> {
9090
),
9191
ExprKind::Async(capture_clause, closure_node_id, ref block) => {
9292
self.make_async_expr(capture_clause, closure_node_id, None, block.span, |this| {
93-
this.with_new_scopes(|this| {
94-
let block = this.lower_block(block, false);
95-
this.expr_block(block, ThinVec::new())
96-
})
93+
this.with_new_scopes(|this| this.lower_block_expr(block))
9794
})
9895
}
9996
ExprKind::Await(ref expr) => self.lower_expr_await(e.span, expr),
@@ -284,8 +281,7 @@ impl LoweringContext<'_> {
284281
let else_arm = self.arm(hir_vec![else_pat], P(else_expr));
285282

286283
// Handle then + scrutinee:
287-
let then_blk = self.lower_block(then, false);
288-
let then_expr = self.expr_block(then_blk, ThinVec::new());
284+
let then_expr = self.lower_block_expr(then);
289285
let (then_pat, scrutinee, desugar) = match cond.node {
290286
// `<pat> => <then>`:
291287
ExprKind::Let(ref pat, ref scrutinee) => {
@@ -335,8 +331,7 @@ impl LoweringContext<'_> {
335331
};
336332

337333
// Handle then + scrutinee:
338-
let then_blk = self.lower_block(body, false);
339-
let then_expr = self.expr_block(then_blk, ThinVec::new());
334+
let then_expr = self.lower_block_expr(body);
340335
let (then_pat, scrutinee, desugar, source) = match cond.node {
341336
ExprKind::Let(ref pat, ref scrutinee) => {
342337
// to:

src/librustc/hir/lowering/item.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,10 +1071,7 @@ impl LoweringContext<'_> {
10711071
}
10721072

10731073
fn lower_fn_body_block(&mut self, decl: &FnDecl, body: &Block) -> hir::BodyId {
1074-
self.lower_fn_body(decl, |this| {
1075-
let body = this.lower_block(body, false);
1076-
this.expr_block(body, ThinVec::new())
1077-
})
1074+
self.lower_fn_body(decl, |this| this.lower_block_expr(body))
10781075
}
10791076

10801077
pub(super) fn lower_const_body(&mut self, expr: &Expr) -> hir::BodyId {
@@ -1220,8 +1217,7 @@ impl LoweringContext<'_> {
12201217
CaptureBy::Value, closure_id, None, body.span,
12211218
|this| {
12221219
// Create a block from the user's function body:
1223-
let user_body = this.lower_block(body, false);
1224-
let user_body = this.expr_block(user_body, ThinVec::new());
1220+
let user_body = this.lower_block_expr(body);
12251221

12261222
// Transform into `drop-temps { <user-body> }`, an expression:
12271223
let desugared_span = this.mark_span_with_reason(

0 commit comments

Comments
 (0)