@@ -3278,7 +3278,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3278
3278
span : Span ,
3279
3279
variant : & ' tcx ty:: VariantDef ,
3280
3280
ast_fields : & ' gcx [ hir:: Field ] ,
3281
- check_completeness : bool ) {
3281
+ check_completeness : bool ) -> bool {
3282
3282
let tcx = self . tcx ;
3283
3283
3284
3284
let adt_ty_hint =
@@ -3380,6 +3380,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3380
3380
truncated_fields_error) )
3381
3381
. emit ( ) ;
3382
3382
}
3383
+ error_happened
3383
3384
}
3384
3385
3385
3386
fn check_struct_fields_on_error ( & self ,
@@ -3478,24 +3479,29 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3478
3479
}
3479
3480
}
3480
3481
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 ( ) ) ;
3483
3484
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
+ }
3499
3505
}
3500
3506
}
3501
3507
}
0 commit comments