]> git.lizzy.rs Git - rust.git/commitdiff
typeck/pat.rs: extract `check_pat_box`.
authorMazdak Farrokhzad <twingoow@gmail.com>
Sat, 24 Aug 2019 02:39:23 +0000 (04:39 +0200)
committerMazdak Farrokhzad <twingoow@gmail.com>
Sat, 24 Aug 2019 17:15:31 +0000 (19:15 +0200)
src/librustc_typeck/check/pat.rs

index be128ea358e7ed21ed37f7b2de44b2c1eb7eca21..f740dc73db5402bfb1cc4848531f501d5dc4e282 100644 (file)
@@ -108,23 +108,7 @@ pub fn check_pat_walk(
                 self.check_pat_tuple(pat.span, elements, ddpos, expected, def_bm, discrim_span)
             }
             PatKind::Box(ref inner) => {
-                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(pat.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(pat.span, expected, uniq_ty, discrim_span);
-                    self.check_pat_walk(&inner, inner_ty, def_bm, discrim_span);
-                    uniq_ty
-                } else {
-                    self.check_pat_walk(&inner, tcx.types.err, def_bm, discrim_span);
-                    tcx.types.err
-                }
+                self.check_pat_box(pat.span, inner, expected, def_bm, discrim_span)
             }
             PatKind::Ref(ref inner, mutbl) => {
                 let expected = self.shallow_resolve(expected);
@@ -1047,4 +1031,32 @@ fn check_struct_pat_fields(
         }
         no_field_errors
     }
+
+    fn check_pat_box(
+        &self,
+        span: Span,
+        inner: &'tcx hir::Pat,
+        expected: Ty<'tcx>,
+        def_bm: ty::BindingMode,
+        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) {
+            // 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_walk(&inner, inner_ty, def_bm, discrim_span);
+            uniq_ty
+        } else {
+            self.check_pat_walk(&inner, tcx.types.err, def_bm, discrim_span);
+            tcx.types.err
+        }
+    }
 }