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