@@ -108,23 +108,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
108108 self . check_pat_tuple ( pat. span , elements, ddpos, expected, def_bm, discrim_span)
109109 }
110110 PatKind :: Box ( ref inner) => {
111- let inner_ty = self . next_ty_var ( TypeVariableOrigin {
112- kind : TypeVariableOriginKind :: TypeInference ,
113- span : inner. span ,
114- } ) ;
115- let uniq_ty = tcx. mk_box ( inner_ty) ;
116-
117- if self . check_dereferencable ( pat. span , expected, & inner) {
118- // Here, `demand::subtype` is good enough, but I don't
119- // think any errors can be introduced by using
120- // `demand::eqtype`.
121- self . demand_eqtype_pat ( pat. span , expected, uniq_ty, discrim_span) ;
122- self . check_pat_walk ( & inner, inner_ty, def_bm, discrim_span) ;
123- uniq_ty
124- } else {
125- self . check_pat_walk ( & inner, tcx. types . err , def_bm, discrim_span) ;
126- tcx. types . err
127- }
111+ self . check_pat_box ( pat. span , inner, expected, def_bm, discrim_span)
128112 }
129113 PatKind :: Ref ( ref inner, mutbl) => {
130114 let expected = self . shallow_resolve ( expected) ;
@@ -1047,4 +1031,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10471031 }
10481032 no_field_errors
10491033 }
1034+
1035+ fn check_pat_box (
1036+ & self ,
1037+ span : Span ,
1038+ inner : & ' tcx hir:: Pat ,
1039+ expected : Ty < ' tcx > ,
1040+ def_bm : ty:: BindingMode ,
1041+ discrim_span : Option < Span > ,
1042+ ) -> Ty < ' tcx > {
1043+ let tcx = self . tcx ;
1044+ let inner_ty = self . next_ty_var ( TypeVariableOrigin {
1045+ kind : TypeVariableOriginKind :: TypeInference ,
1046+ span : inner. span ,
1047+ } ) ;
1048+ let uniq_ty = tcx. mk_box ( inner_ty) ;
1049+
1050+ if self . check_dereferencable ( span, expected, & inner) {
1051+ // Here, `demand::subtype` is good enough, but I don't
1052+ // think any errors can be introduced by using
1053+ // `demand::eqtype`.
1054+ self . demand_eqtype_pat ( span, expected, uniq_ty, discrim_span) ;
1055+ self . check_pat_walk ( & inner, inner_ty, def_bm, discrim_span) ;
1056+ uniq_ty
1057+ } else {
1058+ self . check_pat_walk ( & inner, tcx. types . err , def_bm, discrim_span) ;
1059+ tcx. types . err
1060+ }
1061+ }
10501062}
0 commit comments