]> git.lizzy.rs Git - rust.git/commitdiff
lowering: extract lower_expr_try_block
authorMazdak Farrokhzad <twingoow@gmail.com>
Sat, 10 Aug 2019 13:09:18 +0000 (15:09 +0200)
committerMazdak Farrokhzad <twingoow@gmail.com>
Sat, 10 Aug 2019 18:24:42 +0000 (20:24 +0200)
src/librustc/hir/lowering/expr.rs

index 2ac8889e0040f3a3e386a32da1b9af7aa2b04512..711ec662301c160268141ae7406758640568587d 100644 (file)
@@ -225,31 +225,7 @@ pub(super) fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
                     hir::LoopSource::Loop,
                 )
             }),
-            ExprKind::TryBlock(ref body) => {
-                self.with_catch_scope(body.id, |this| {
-                    let unstable_span = this.mark_span_with_reason(
-                        DesugaringKind::TryBlock,
-                        body.span,
-                        this.allow_try_trait.clone(),
-                    );
-                    let mut block = this.lower_block(body, true).into_inner();
-                    let tail = block.expr.take().map_or_else(
-                        || {
-                            let span = this.sess.source_map().end_point(unstable_span);
-                            hir::Expr {
-                                span,
-                                node: hir::ExprKind::Tup(hir_vec![]),
-                                attrs: ThinVec::new(),
-                                hir_id: this.next_id(),
-                            }
-                        },
-                        |x: P<hir::Expr>| x.into_inner(),
-                    );
-                    block.expr = Some(this.wrap_in_try_constructor(
-                        sym::from_ok, tail, unstable_span));
-                    hir::ExprKind::Block(P(block), None)
-                })
-            }
+            ExprKind::TryBlock(ref body) => self.lower_expr_try_block(body),
             ExprKind::Match(ref expr, ref arms) => hir::ExprKind::Match(
                 P(self.lower_expr(expr)),
                 arms.iter().map(|x| self.lower_arm(x)).collect(),
@@ -375,6 +351,23 @@ pub(super) fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
         }
     }
 
+    fn lower_expr_try_block(&mut self, body: &Block) -> hir::ExprKind {
+        self.with_catch_scope(body.id, |this| {
+            let unstable_span = this.mark_span_with_reason(
+                DesugaringKind::TryBlock,
+                body.span,
+                this.allow_try_trait.clone(),
+            );
+            let mut block = this.lower_block(body, true).into_inner();
+            let tail = block.expr.take().map_or_else(
+                || this.expr_unit(this.sess.source_map().end_point(unstable_span)),
+                |x: P<hir::Expr>| x.into_inner(),
+            );
+            block.expr = Some(this.wrap_in_try_constructor(sym::from_ok, tail, unstable_span));
+            hir::ExprKind::Block(P(block), None)
+        })
+    }
+
     /// Desugar `<expr>.await` into:
     /// ```rust
     /// {