@@ -1982,27 +1982,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19821982
19831983 fn check_expr_tuple (
19841984 & self ,
1985- elts : & ' tcx [ hir:: Expr < ' tcx > ] ,
1985+ elements : & ' tcx [ hir:: Expr < ' tcx > ] ,
19861986 expected : Expectation < ' tcx > ,
19871987 expr : & ' tcx hir:: Expr < ' tcx > ,
19881988 ) -> Ty < ' tcx > {
1989- let flds = expected. only_has_type ( self ) . and_then ( |ty| {
1990- let ty = self . try_structurally_resolve_type ( expr. span , ty) ;
1991- match ty. kind ( ) {
1992- ty:: Tuple ( flds) => Some ( & flds[ ..] ) ,
1993- _ => None ,
1994- }
1989+ let mut expectations = expected
1990+ . only_has_type ( self )
1991+ . and_then ( |ty| self . try_structurally_resolve_type ( expr. span , ty) . tuple ( ) )
1992+ . unwrap_or_default ( )
1993+ . iter ( ) ;
1994+
1995+ let elements = elements. iter ( ) . map ( |e| {
1996+ let ty = expectations. next ( ) . unwrap_or_else ( || self . next_ty_var ( e. span ) ) ;
1997+ self . check_expr_coercible_to_type ( e, ty, None ) ;
1998+ ty
19951999 } ) ;
19962000
1997- let elt_ts_iter = elts. iter ( ) . enumerate ( ) . map ( |( i, e) | match flds {
1998- Some ( fs) if i < fs. len ( ) => {
1999- let ety = fs[ i] ;
2000- self . check_expr_coercible_to_type ( e, ety, None ) ;
2001- ety
2002- }
2003- _ => self . check_expr_with_expectation ( e, NoExpectation ) ,
2004- } ) ;
2005- let tuple = Ty :: new_tup_from_iter ( self . tcx , elt_ts_iter) ;
2001+ let tuple = Ty :: new_tup_from_iter ( self . tcx , elements) ;
2002+
20062003 if let Err ( guar) = tuple. error_reported ( ) {
20072004 Ty :: new_error ( self . tcx , guar)
20082005 } else {
0 commit comments