about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-08-25 00:27:55 +0200
committerMazdak Farrokhzad <twingoow@gmail.com>2019-08-25 00:27:55 +0200
commit5a7e1cb46a05fd176e5488beb58f72a05f4b1a0d (patch)
treefe3546f1e24394a203cacf342d5d7417819fed3f
parent4f7532765967ea174816a23c11188aa8c7865966 (diff)
typeck/pat.rs: dedup in `check_pat_box`.
-rw-r--r--src/librustc_typeck/check/pat.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs
index 7506cbdd510..3f6fc95360a 100644
--- a/src/librustc_typeck/check/pat.rs
+++ b/src/librustc_typeck/check/pat.rs
@@ -952,22 +952,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         discrim_span: Option<Span>,
     ) -> Ty<'tcx> {
         let tcx = self.tcx;
-        let inner_ty = self.next_ty_var(TypeVariableOrigin {
-            kind: TypeVariableOriginKind::TypeInference,
-            span: inner.span,
-        });
-        let uniq_ty = tcx.mk_box(inner_ty);
-
-        if self.check_dereferencable(span, expected, &inner) {
+        let (box_ty, inner_ty) = if self.check_dereferencable(span, expected, &inner) {
             // Here, `demand::subtype` is good enough, but I don't
             // think any errors can be introduced by using `demand::eqtype`.
-            self.demand_eqtype_pat(span, expected, uniq_ty, discrim_span);
-            self.check_pat(&inner, inner_ty, def_bm, discrim_span);
-            uniq_ty
+            let inner_ty = self.next_ty_var(TypeVariableOrigin {
+                kind: TypeVariableOriginKind::TypeInference,
+                span: inner.span,
+            });
+            let box_ty = tcx.mk_box(inner_ty);
+            self.demand_eqtype_pat(span, expected, box_ty, discrim_span);
+            (box_ty, inner_ty)
         } else {
-            self.check_pat(&inner, tcx.types.err, def_bm, discrim_span);
-            tcx.types.err
-        }
+            (tcx.types.err, tcx.types.err)
+        };
+        self.check_pat(&inner, inner_ty, def_bm, discrim_span);
+        box_ty
     }
 
     fn check_pat_ref(