]> git.lizzy.rs Git - rust.git/commitdiff
typeck/expr.rs: extract out check_expr_box.
authorMazdak Farrokhzad <twingoow@gmail.com>
Fri, 14 Jun 2019 23:36:09 +0000 (01:36 +0200)
committerMazdak Farrokhzad <twingoow@gmail.com>
Fri, 14 Jun 2019 23:36:09 +0000 (01:36 +0200)
src/librustc_typeck/check/expr.rs

index 48c1c0b36ffbfece413ef1570f3497cb4fef2f6a..15a09c0cc673153966e05f69211658ffaac2f8dd 100644 (file)
@@ -50,17 +50,8 @@ pub(super) fn check_expr_kind(
         let id = expr.hir_id;
         match expr.node {
             ExprKind::Box(ref subexpr) => {
-                let expected_inner = expected.to_option(self).map_or(NoExpectation, |ty| {
-                    match ty.sty {
-                        ty::Adt(def, _) if def.is_box()
-                            => Expectation::rvalue_hint(self, ty.boxed_ty()),
-                        _ => NoExpectation
-                    }
-                });
-                let referent_ty = self.check_expr_with_expectation(subexpr, expected_inner);
-                tcx.mk_box(referent_ty)
+                self.check_expr_box(subexpr, expected)
             }
-
             ExprKind::Lit(ref lit) => {
                 self.check_lit(&lit, expected)
             }
@@ -703,4 +694,16 @@ pub(super) fn check_expr_kind(
             }
         }
     }
+
+    fn check_expr_box(&self, expr: &'tcx hir::Expr, expected: Expectation<'tcx>) -> Ty<'tcx> {
+        let expected_inner = expected.to_option(self).map_or(NoExpectation, |ty| {
+            match ty.sty {
+                ty::Adt(def, _) if def.is_box()
+                    => Expectation::rvalue_hint(self, ty.boxed_ty()),
+                _ => NoExpectation
+            }
+        });
+        let referent_ty = self.check_expr_with_expectation(expr, expected_inner);
+        self.tcx.mk_box(referent_ty)
+    }
 }