@@ -105,48 +105,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
105
105
expected_ty
106
106
}
107
107
PatKind :: Tuple ( ref elements, ddpos) => {
108
- let mut expected_len = elements. len ( ) ;
109
- if ddpos. is_some ( ) {
110
- // Require known type only when `..` is present.
111
- if let ty:: Tuple ( ref tys) =
112
- self . structurally_resolved_type ( pat. span , expected) . sty {
113
- expected_len = tys. len ( ) ;
114
- }
115
- }
116
- let max_len = cmp:: max ( expected_len, elements. len ( ) ) ;
117
-
118
- let element_tys_iter = ( 0 ..max_len) . map ( |_| {
119
- Kind :: from ( self . next_ty_var (
120
- // FIXME: `MiscVariable` for now -- obtaining the span and name information
121
- // from all tuple elements isn't trivial.
122
- TypeVariableOrigin {
123
- kind : TypeVariableOriginKind :: TypeInference ,
124
- span : pat. span ,
125
- } ,
126
- ) )
127
- } ) ;
128
- let element_tys = tcx. mk_substs ( element_tys_iter) ;
129
- let pat_ty = tcx. mk_ty ( ty:: Tuple ( element_tys) ) ;
130
- if let Some ( mut err) = self . demand_eqtype_diag ( pat. span , expected, pat_ty) {
131
- err. emit ( ) ;
132
- // Walk subpatterns with an expected type of `err` in this case to silence
133
- // further errors being emitted when using the bindings. #50333
134
- let element_tys_iter = ( 0 ..max_len) . map ( |_| tcx. types . err ) ;
135
- for ( _, elem) in elements. iter ( ) . enumerate_and_adjust ( max_len, ddpos) {
136
- self . check_pat_walk ( elem, & tcx. types . err , def_bm, discrim_span) ;
137
- }
138
- tcx. mk_tup ( element_tys_iter)
139
- } else {
140
- for ( i, elem) in elements. iter ( ) . enumerate_and_adjust ( max_len, ddpos) {
141
- self . check_pat_walk (
142
- elem,
143
- & element_tys[ i] . expect_ty ( ) ,
144
- def_bm,
145
- discrim_span,
146
- ) ;
147
- }
148
- pat_ty
149
- }
108
+ self . check_pat_tuple ( pat. span , elements, ddpos, expected, def_bm, discrim_span)
150
109
}
151
110
PatKind :: Box ( ref inner) => {
152
111
let inner_ty = self . next_ty_var ( TypeVariableOrigin {
@@ -807,7 +766,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
807
766
pat. hir_id ) ;
808
767
if !pat_ty. is_fn ( ) {
809
768
report_unexpected_res ( res) ;
810
- return self . tcx . types . err ;
769
+ return tcx. types . err ;
811
770
}
812
771
813
772
let variant = match res {
@@ -833,8 +792,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
833
792
self . demand_eqtype_pat ( pat. span , expected, pat_ty, match_arm_pat_span) ;
834
793
835
794
// Type-check subpatterns.
836
- if subpats. len ( ) == variant. fields . len ( ) ||
837
- subpats. len ( ) < variant. fields . len ( ) && ddpos. is_some ( ) {
795
+ if subpats. len ( ) == variant. fields . len ( )
796
+ || subpats. len ( ) < variant. fields . len ( ) && ddpos. is_some ( )
797
+ {
838
798
let substs = match pat_ty. sty {
839
799
ty:: Adt ( _, substs) => substs,
840
800
_ => bug ! ( "unexpected pattern type {:?}" , pat_ty) ,
@@ -861,6 +821,59 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
861
821
pat_ty
862
822
}
863
823
824
+ fn check_pat_tuple (
825
+ & self ,
826
+ span : Span ,
827
+ elements : & ' tcx [ P < hir:: Pat > ] ,
828
+ ddpos : Option < usize > ,
829
+ expected : Ty < ' tcx > ,
830
+ def_bm : ty:: BindingMode ,
831
+ discrim_span : Option < Span > ,
832
+ ) -> Ty < ' tcx > {
833
+ let tcx = self . tcx ;
834
+ let mut expected_len = elements. len ( ) ;
835
+ if ddpos. is_some ( ) {
836
+ // Require known type only when `..` is present.
837
+ if let ty:: Tuple ( ref tys) = self . structurally_resolved_type ( span, expected) . sty {
838
+ expected_len = tys. len ( ) ;
839
+ }
840
+ }
841
+ let max_len = cmp:: max ( expected_len, elements. len ( ) ) ;
842
+
843
+ let element_tys_iter = ( 0 ..max_len) . map ( |_| {
844
+ Kind :: from ( self . next_ty_var (
845
+ // FIXME: `MiscVariable` for now -- obtaining the span and name information
846
+ // from all tuple elements isn't trivial.
847
+ TypeVariableOrigin {
848
+ kind : TypeVariableOriginKind :: TypeInference ,
849
+ span,
850
+ } ,
851
+ ) )
852
+ } ) ;
853
+ let element_tys = tcx. mk_substs ( element_tys_iter) ;
854
+ let pat_ty = tcx. mk_ty ( ty:: Tuple ( element_tys) ) ;
855
+ if let Some ( mut err) = self . demand_eqtype_diag ( span, expected, pat_ty) {
856
+ err. emit ( ) ;
857
+ // Walk subpatterns with an expected type of `err` in this case to silence
858
+ // further errors being emitted when using the bindings. #50333
859
+ let element_tys_iter = ( 0 ..max_len) . map ( |_| tcx. types . err ) ;
860
+ for ( _, elem) in elements. iter ( ) . enumerate_and_adjust ( max_len, ddpos) {
861
+ self . check_pat_walk ( elem, & tcx. types . err , def_bm, discrim_span) ;
862
+ }
863
+ tcx. mk_tup ( element_tys_iter)
864
+ } else {
865
+ for ( i, elem) in elements. iter ( ) . enumerate_and_adjust ( max_len, ddpos) {
866
+ self . check_pat_walk (
867
+ elem,
868
+ & element_tys[ i] . expect_ty ( ) ,
869
+ def_bm,
870
+ discrim_span,
871
+ ) ;
872
+ }
873
+ pat_ty
874
+ }
875
+ }
876
+
864
877
fn check_struct_pat_fields (
865
878
& self ,
866
879
adt_ty : Ty < ' tcx > ,
0 commit comments