@@ -1939,27 +1939,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19391939
19401940 fn check_expr_tuple (
19411941 & self ,
1942- elts : & ' tcx [ hir:: Expr < ' tcx > ] ,
1942+ elements : & ' tcx [ hir:: Expr < ' tcx > ] ,
19431943 expected : Expectation < ' tcx > ,
19441944 expr : & ' tcx hir:: Expr < ' tcx > ,
19451945 ) -> Ty < ' tcx > {
1946- let flds = expected. only_has_type ( self ) . and_then ( |ty| {
1947- let ty = self . try_structurally_resolve_type ( expr. span , ty) ;
1948- match ty. kind ( ) {
1949- ty:: Tuple ( flds) => Some ( & flds[ ..] ) ,
1950- _ => None ,
1951- }
1946+ let mut expectations = expected
1947+ . only_has_type ( self )
1948+ . and_then ( |ty| self . try_structurally_resolve_type ( expr. span , ty) . tuple ( ) )
1949+ . unwrap_or_default ( )
1950+ . iter ( ) ;
1951+
1952+ let elements = elements. iter ( ) . map ( |e| {
1953+ let ty = expectations. next ( ) . unwrap_or_else ( || self . next_ty_var ( e. span ) ) ;
1954+ self . check_expr_coercible_to_type ( e, ty, None ) ;
1955+ ty
19521956 } ) ;
19531957
1954- let elt_ts_iter = elts. iter ( ) . enumerate ( ) . map ( |( i, e) | match flds {
1955- Some ( fs) if i < fs. len ( ) => {
1956- let ety = fs[ i] ;
1957- self . check_expr_coercible_to_type ( e, ety, None ) ;
1958- ety
1959- }
1960- _ => self . check_expr_with_expectation ( e, NoExpectation ) ,
1961- } ) ;
1962- let tuple = Ty :: new_tup_from_iter ( self . tcx , elt_ts_iter) ;
1958+ let tuple = Ty :: new_tup_from_iter ( self . tcx , elements) ;
1959+
19631960 if let Err ( guar) = tuple. error_reported ( ) {
19641961 Ty :: new_error ( self . tcx , guar)
19651962 } else {
0 commit comments