@@ -1792,27 +1792,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17921792
17931793 fn check_expr_tuple (
17941794 & self ,
1795- elts : & ' tcx [ hir:: Expr < ' tcx > ] ,
1795+ elements : & ' tcx [ hir:: Expr < ' tcx > ] ,
17961796 expected : Expectation < ' tcx > ,
17971797 expr : & ' tcx hir:: Expr < ' tcx > ,
17981798 ) -> Ty < ' tcx > {
1799- let flds = expected. only_has_type ( self ) . and_then ( |ty| {
1800- let ty = self . try_structurally_resolve_type ( expr. span , ty) ;
1801- match ty. kind ( ) {
1802- ty:: Tuple ( flds) => Some ( & flds[ ..] ) ,
1803- _ => None ,
1804- }
1799+ let mut expectations = expected
1800+ . only_has_type ( self )
1801+ . and_then ( |ty| self . try_structurally_resolve_type ( expr. span , ty) . opt_tuple_fields ( ) )
1802+ . unwrap_or_default ( )
1803+ . iter ( ) ;
1804+
1805+ let elements = elements. iter ( ) . map ( |e| {
1806+ let ty = expectations. next ( ) . unwrap_or_else ( || self . next_ty_var ( e. span ) ) ;
1807+ self . check_expr_coercible_to_type ( e, ty, None ) ;
1808+ ty
18051809 } ) ;
18061810
1807- let elt_ts_iter = elts. iter ( ) . enumerate ( ) . map ( |( i, e) | match flds {
1808- Some ( fs) if i < fs. len ( ) => {
1809- let ety = fs[ i] ;
1810- self . check_expr_coercible_to_type ( e, ety, None ) ;
1811- ety
1812- }
1813- _ => self . check_expr_with_expectation ( e, NoExpectation ) ,
1814- } ) ;
1815- let tuple = Ty :: new_tup_from_iter ( self . tcx , elt_ts_iter) ;
1811+ let tuple = Ty :: new_tup_from_iter ( self . tcx , elements) ;
1812+
18161813 if let Err ( guar) = tuple. error_reported ( ) {
18171814 Ty :: new_error ( self . tcx , guar)
18181815 } else {
0 commit comments