@@ -3278,7 +3278,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
32783278 span : Span ,
32793279 variant : & ' tcx ty:: VariantDef ,
32803280 ast_fields : & ' gcx [ hir:: Field ] ,
3281- check_completeness : bool ) {
3281+ check_completeness : bool ) -> bool {
32823282 let tcx = self . tcx ;
32833283
32843284 let adt_ty_hint =
@@ -3380,6 +3380,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
33803380 truncated_fields_error) )
33813381 . emit ( ) ;
33823382 }
3383+ error_happened
33833384 }
33843385
33853386 fn check_struct_fields_on_error ( & self ,
@@ -3478,24 +3479,29 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
34783479 }
34793480 }
34803481
3481- self . check_expr_struct_fields ( struct_ty, expected, expr. id , path_span, variant , fields ,
3482- base_expr. is_none ( ) ) ;
3482+ let error_happened = self . check_expr_struct_fields ( struct_ty, expected, expr. id , path_span,
3483+ variant , fields , base_expr. is_none ( ) ) ;
34833484 if let & Some ( ref base_expr) = base_expr {
3484- self . check_expr_has_type_or_error ( base_expr, struct_ty) ;
3485- match struct_ty. sty {
3486- ty:: TyAdt ( adt, substs) if adt. is_struct ( ) => {
3487- let fru_field_types = adt. non_enum_variant ( ) . fields . iter ( ) . map ( |f| {
3488- self . normalize_associated_types_in ( expr. span , & f. ty ( self . tcx , substs) )
3489- } ) . collect ( ) ;
3490-
3491- self . tables
3492- . borrow_mut ( )
3493- . fru_field_types_mut ( )
3494- . insert ( expr. hir_id , fru_field_types) ;
3495- }
3496- _ => {
3497- span_err ! ( self . tcx. sess, base_expr. span, E0436 ,
3498- "functional record update syntax requires a struct" ) ;
3485+ // If check_expr_struct_fields hit an error, do not attempt to populate
3486+ // the fields with the base_expr. This could cause us to hit errors later
3487+ // when certain fields are assumed to exist that in fact do not.
3488+ if !error_happened {
3489+ self . check_expr_has_type_or_error ( base_expr, struct_ty) ;
3490+ match struct_ty. sty {
3491+ ty:: TyAdt ( adt, substs) if adt. is_struct ( ) => {
3492+ let fru_field_types = adt. non_enum_variant ( ) . fields . iter ( ) . map ( |f| {
3493+ self . normalize_associated_types_in ( expr. span , & f. ty ( self . tcx , substs) )
3494+ } ) . collect ( ) ;
3495+
3496+ self . tables
3497+ . borrow_mut ( )
3498+ . fru_field_types_mut ( )
3499+ . insert ( expr. hir_id , fru_field_types) ;
3500+ }
3501+ _ => {
3502+ span_err ! ( self . tcx. sess, base_expr. span, E0436 ,
3503+ "functional record update syntax requires a struct" ) ;
3504+ }
34993505 }
35003506 }
35013507 }
0 commit comments