@@ -990,10 +990,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
990990 let _ = self . demand_eqtype_pat ( pat. span , expected, pat_ty, pat_info. top_info ) ;
991991
992992 // Type-check subpatterns.
993- if self . check_struct_pat_fields ( pat_ty, pat, variant, fields, has_rest_pat, pat_info) {
994- pat_ty
995- } else {
996- Ty :: new_misc_error ( self . tcx )
993+ match self . check_struct_pat_fields ( pat_ty, pat, variant, fields, has_rest_pat, pat_info) {
994+ Ok ( ( ) ) => pat_ty,
995+ Err ( guar) => Ty :: new_error ( self . tcx , guar) ,
997996 }
998997 }
999998
@@ -1469,7 +1468,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14691468 fields : & ' tcx [ hir:: PatField < ' tcx > ] ,
14701469 has_rest_pat : bool ,
14711470 pat_info : PatInfo < ' tcx , ' _ > ,
1472- ) -> bool {
1471+ ) -> Result < ( ) , ErrorGuaranteed > {
14731472 let tcx = self . tcx ;
14741473
14751474 let ty:: Adt ( adt, args) = adt_ty. kind ( ) else {
@@ -1485,7 +1484,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14851484
14861485 // Keep track of which fields have already appeared in the pattern.
14871486 let mut used_fields = FxHashMap :: default ( ) ;
1488- let mut no_field_errors = true ;
1487+ let mut result = Ok ( ( ) ) ;
14891488
14901489 let mut inexistent_fields = vec ! [ ] ;
14911490 // Typecheck each field.
@@ -1494,8 +1493,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14941493 let ident = tcx. adjust_ident ( field. ident , variant. def_id ) ;
14951494 let field_ty = match used_fields. entry ( ident) {
14961495 Occupied ( occupied) => {
1497- no_field_errors = false ;
14981496 let guar = self . error_field_already_bound ( span, field. ident , * occupied. get ( ) ) ;
1497+ result = Err ( guar) ;
14991498 Ty :: new_error ( tcx, guar)
15001499 }
15011500 Vacant ( vacant) => {
@@ -1510,7 +1509,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15101509 } )
15111510 . unwrap_or_else ( || {
15121511 inexistent_fields. push ( field) ;
1513- no_field_errors = false ;
15141512 Ty :: new_misc_error ( tcx)
15151513 } )
15161514 }
@@ -1589,40 +1587,34 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15891587 // `Foo { a, b }` when it should have been `Foo(a, b)`.
15901588 i. delay_as_bug ( ) ;
15911589 u. delay_as_bug ( ) ;
1592- e. emit ( ) ;
1590+ Err ( e. emit ( ) )
15931591 } else {
15941592 i. emit ( ) ;
1595- u. emit ( ) ;
1593+ Err ( u. emit ( ) )
15961594 }
15971595 }
15981596 ( None , Some ( u) ) => {
15991597 if let Some ( e) = self . error_tuple_variant_as_struct_pat ( pat, fields, variant) {
16001598 u. delay_as_bug ( ) ;
1601- e. emit ( ) ;
1599+ Err ( e. emit ( ) )
16021600 } else {
1603- u. emit ( ) ;
1601+ Err ( u. emit ( ) )
16041602 }
16051603 }
1606- ( Some ( err) , None ) => {
1607- err. emit ( ) ;
1604+ ( Some ( err) , None ) => Err ( err. emit ( ) ) ,
1605+ ( None , None ) => {
1606+ self . error_tuple_variant_index_shorthand ( variant, pat, fields) ?;
1607+ result
16081608 }
1609- ( None , None )
1610- if let Some ( err) =
1611- self . error_tuple_variant_index_shorthand ( variant, pat, fields) =>
1612- {
1613- err. emit ( ) ;
1614- }
1615- ( None , None ) => { }
16161609 }
1617- no_field_errors
16181610 }
16191611
16201612 fn error_tuple_variant_index_shorthand (
16211613 & self ,
16221614 variant : & VariantDef ,
16231615 pat : & ' _ Pat < ' _ > ,
16241616 fields : & [ hir:: PatField < ' _ > ] ,
1625- ) -> Option < Diag < ' _ > > {
1617+ ) -> Result < ( ) , ErrorGuaranteed > {
16261618 // if this is a tuple struct, then all field names will be numbers
16271619 // so if any fields in a struct pattern use shorthand syntax, they will
16281620 // be invalid identifiers (for example, Foo { 0, 1 }).
@@ -1644,10 +1636,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16441636 format ! ( "({})" , self . get_suggested_tuple_struct_pattern( fields, variant) ) ,
16451637 Applicability :: MaybeIncorrect ,
16461638 ) ;
1647- return Some ( err) ;
1639+ return Err ( err. emit ( ) ) ;
16481640 }
16491641 }
1650- None
1642+ Ok ( ( ) )
16511643 }
16521644
16531645 fn error_foreign_non_exhaustive_spat ( & self , pat : & Pat < ' _ > , descr : & str , no_fields : bool ) {
0 commit comments