@@ -131,34 +131,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
131
131
self . check_expr_repeat ( element, count, expected, expr)
132
132
}
133
133
ExprKind :: Tup ( ref elts) => {
134
- let flds = expected. only_has_type ( self ) . and_then ( |ty| {
135
- let ty = self . resolve_type_vars_with_obligations ( ty) ;
136
- match ty. sty {
137
- ty:: Tuple ( ref flds) => Some ( & flds[ ..] ) ,
138
- _ => None
139
- }
140
- } ) ;
141
-
142
- let elt_ts_iter = elts. iter ( ) . enumerate ( ) . map ( |( i, e) | {
143
- let t = match flds {
144
- Some ( ref fs) if i < fs. len ( ) => {
145
- let ety = fs[ i] . expect_ty ( ) ;
146
- self . check_expr_coercable_to_type ( & e, ety) ;
147
- ety
148
- }
149
- _ => {
150
- self . check_expr_with_expectation ( & e, NoExpectation )
151
- }
152
- } ;
153
- t
154
- } ) ;
155
- let tuple = tcx. mk_tup ( elt_ts_iter) ;
156
- if tuple. references_error ( ) {
157
- tcx. types . err
158
- } else {
159
- self . require_type_is_sized ( tuple, expr. span , traits:: TupleInitializerSized ) ;
160
- tuple
161
- }
134
+ self . check_expr_tuple ( elts, expected, expr)
162
135
}
163
136
ExprKind :: Struct ( ref qpath, ref fields, ref base_expr) => {
164
137
self . check_expr_struct ( expr, expected, qpath, fields, base_expr)
@@ -835,4 +808,40 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
835
808
tcx. types . err
836
809
}
837
810
}
811
+
812
+ fn check_expr_tuple (
813
+ & self ,
814
+ elts : & ' tcx [ hir:: Expr ] ,
815
+ expected : Expectation < ' tcx > ,
816
+ expr : & ' tcx hir:: Expr ,
817
+ ) -> Ty < ' tcx > {
818
+ let flds = expected. only_has_type ( self ) . and_then ( |ty| {
819
+ let ty = self . resolve_type_vars_with_obligations ( ty) ;
820
+ match ty. sty {
821
+ ty:: Tuple ( ref flds) => Some ( & flds[ ..] ) ,
822
+ _ => None
823
+ }
824
+ } ) ;
825
+
826
+ let elt_ts_iter = elts. iter ( ) . enumerate ( ) . map ( |( i, e) | {
827
+ let t = match flds {
828
+ Some ( ref fs) if i < fs. len ( ) => {
829
+ let ety = fs[ i] . expect_ty ( ) ;
830
+ self . check_expr_coercable_to_type ( & e, ety) ;
831
+ ety
832
+ }
833
+ _ => {
834
+ self . check_expr_with_expectation ( & e, NoExpectation )
835
+ }
836
+ } ;
837
+ t
838
+ } ) ;
839
+ let tuple = self . tcx . mk_tup ( elt_ts_iter) ;
840
+ if tuple. references_error ( ) {
841
+ self . tcx . types . err
842
+ } else {
843
+ self . require_type_is_sized ( tuple, expr. span , traits:: TupleInitializerSized ) ;
844
+ tuple
845
+ }
846
+ }
838
847
}
0 commit comments