@@ -990,10 +990,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
990
990
let _ = self . demand_eqtype_pat ( pat. span , expected, pat_ty, pat_info. top_info ) ;
991
991
992
992
// 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) ,
997
996
}
998
997
}
999
998
@@ -1469,7 +1468,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1469
1468
fields : & ' tcx [ hir:: PatField < ' tcx > ] ,
1470
1469
has_rest_pat : bool ,
1471
1470
pat_info : PatInfo < ' tcx , ' _ > ,
1472
- ) -> bool {
1471
+ ) -> Result < ( ) , ErrorGuaranteed > {
1473
1472
let tcx = self . tcx ;
1474
1473
1475
1474
let ty:: Adt ( adt, args) = adt_ty. kind ( ) else {
@@ -1485,7 +1484,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1485
1484
1486
1485
// Keep track of which fields have already appeared in the pattern.
1487
1486
let mut used_fields = FxHashMap :: default ( ) ;
1488
- let mut no_field_errors = true ;
1487
+ let mut result = Ok ( ( ) ) ;
1489
1488
1490
1489
let mut inexistent_fields = vec ! [ ] ;
1491
1490
// Typecheck each field.
@@ -1494,8 +1493,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1494
1493
let ident = tcx. adjust_ident ( field. ident , variant. def_id ) ;
1495
1494
let field_ty = match used_fields. entry ( ident) {
1496
1495
Occupied ( occupied) => {
1497
- no_field_errors = false ;
1498
1496
let guar = self . error_field_already_bound ( span, field. ident , * occupied. get ( ) ) ;
1497
+ result = Err ( guar) ;
1499
1498
Ty :: new_error ( tcx, guar)
1500
1499
}
1501
1500
Vacant ( vacant) => {
@@ -1510,7 +1509,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1510
1509
} )
1511
1510
. unwrap_or_else ( || {
1512
1511
inexistent_fields. push ( field) ;
1513
- no_field_errors = false ;
1514
1512
Ty :: new_misc_error ( tcx)
1515
1513
} )
1516
1514
}
@@ -1589,40 +1587,34 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1589
1587
// `Foo { a, b }` when it should have been `Foo(a, b)`.
1590
1588
i. delay_as_bug ( ) ;
1591
1589
u. delay_as_bug ( ) ;
1592
- e. emit ( ) ;
1590
+ Err ( e. emit ( ) )
1593
1591
} else {
1594
1592
i. emit ( ) ;
1595
- u. emit ( ) ;
1593
+ Err ( u. emit ( ) )
1596
1594
}
1597
1595
}
1598
1596
( None , Some ( u) ) => {
1599
1597
if let Some ( e) = self . error_tuple_variant_as_struct_pat ( pat, fields, variant) {
1600
1598
u. delay_as_bug ( ) ;
1601
- e. emit ( ) ;
1599
+ Err ( e. emit ( ) )
1602
1600
} else {
1603
- u. emit ( ) ;
1601
+ Err ( u. emit ( ) )
1604
1602
}
1605
1603
}
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
1608
1608
}
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 ) => { }
1616
1609
}
1617
- no_field_errors
1618
1610
}
1619
1611
1620
1612
fn error_tuple_variant_index_shorthand (
1621
1613
& self ,
1622
1614
variant : & VariantDef ,
1623
1615
pat : & ' _ Pat < ' _ > ,
1624
1616
fields : & [ hir:: PatField < ' _ > ] ,
1625
- ) -> Option < Diag < ' _ > > {
1617
+ ) -> Result < ( ) , ErrorGuaranteed > {
1626
1618
// if this is a tuple struct, then all field names will be numbers
1627
1619
// so if any fields in a struct pattern use shorthand syntax, they will
1628
1620
// be invalid identifiers (for example, Foo { 0, 1 }).
@@ -1644,10 +1636,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1644
1636
format ! ( "({})" , self . get_suggested_tuple_struct_pattern( fields, variant) ) ,
1645
1637
Applicability :: MaybeIncorrect ,
1646
1638
) ;
1647
- return Some ( err) ;
1639
+ return Err ( err. emit ( ) ) ;
1648
1640
}
1649
1641
}
1650
- None
1642
+ Ok ( ( ) )
1651
1643
}
1652
1644
1653
1645
fn error_foreign_non_exhaustive_spat ( & self , pat : & Pat < ' _ > , descr : & str , no_fields : bool ) {
0 commit comments