Skip to content

Commit 8ddd173

Browse files
committed
lowering: extract lower_expr_try_block
1 parent e450dca commit 8ddd173

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

src/librustc/hir/lowering/expr.rs

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -225,31 +225,7 @@ impl LoweringContext<'_> {
225225
hir::LoopSource::Loop,
226226
)
227227
}),
228-
ExprKind::TryBlock(ref body) => {
229-
self.with_catch_scope(body.id, |this| {
230-
let unstable_span = this.mark_span_with_reason(
231-
DesugaringKind::TryBlock,
232-
body.span,
233-
this.allow_try_trait.clone(),
234-
);
235-
let mut block = this.lower_block(body, true).into_inner();
236-
let tail = block.expr.take().map_or_else(
237-
|| {
238-
let span = this.sess.source_map().end_point(unstable_span);
239-
hir::Expr {
240-
span,
241-
node: hir::ExprKind::Tup(hir_vec![]),
242-
attrs: ThinVec::new(),
243-
hir_id: this.next_id(),
244-
}
245-
},
246-
|x: P<hir::Expr>| x.into_inner(),
247-
);
248-
block.expr = Some(this.wrap_in_try_constructor(
249-
sym::from_ok, tail, unstable_span));
250-
hir::ExprKind::Block(P(block), None)
251-
})
252-
}
228+
ExprKind::TryBlock(ref body) => self.lower_expr_try_block(body),
253229
ExprKind::Match(ref expr, ref arms) => hir::ExprKind::Match(
254230
P(self.lower_expr(expr)),
255231
arms.iter().map(|x| self.lower_arm(x)).collect(),
@@ -375,6 +351,23 @@ impl LoweringContext<'_> {
375351
}
376352
}
377353

354+
fn lower_expr_try_block(&mut self, body: &Block) -> hir::ExprKind {
355+
self.with_catch_scope(body.id, |this| {
356+
let unstable_span = this.mark_span_with_reason(
357+
DesugaringKind::TryBlock,
358+
body.span,
359+
this.allow_try_trait.clone(),
360+
);
361+
let mut block = this.lower_block(body, true).into_inner();
362+
let tail = block.expr.take().map_or_else(
363+
|| this.expr_unit(this.sess.source_map().end_point(unstable_span)),
364+
|x: P<hir::Expr>| x.into_inner(),
365+
);
366+
block.expr = Some(this.wrap_in_try_constructor(sym::from_ok, tail, unstable_span));
367+
hir::ExprKind::Block(P(block), None)
368+
})
369+
}
370+
378371
/// Desugar `<expr>.await` into:
379372
/// ```rust
380373
/// {

0 commit comments

Comments
 (0)