@@ -1532,17 +1532,17 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
1532
1532
if !this. has_private_fields ( def_id) {
1533
1533
// If the fields of the type are private, we shouldn't be suggesting using
1534
1534
// the struct literal syntax at all, as that will cause a subsequent error.
1535
- let field_ids = this. r . field_def_ids ( def_id) ;
1536
- let ( fields, applicability) = match field_ids {
1537
- Some ( field_ids) => {
1538
- let fields = field_ids. iter ( ) . map ( |& id| this. r . tcx . item_name ( id) ) ;
1539
-
1535
+ let fields = this. r . field_idents ( def_id) ;
1536
+ let has_fields = fields. as_ref ( ) . is_some_and ( |f| !f. is_empty ( ) ) ;
1537
+ let ( fields, applicability) = match fields {
1538
+ Some ( fields) => {
1540
1539
let fields = if let Some ( old_fields) = old_fields {
1541
1540
fields
1541
+ . iter ( )
1542
1542
. enumerate ( )
1543
1543
. map ( |( idx, new) | ( new, old_fields. get ( idx) ) )
1544
1544
. map ( |( new, old) | {
1545
- let new = new. to_ident_string ( ) ;
1545
+ let new = new. name . to_ident_string ( ) ;
1546
1546
if let Some ( Some ( old) ) = old
1547
1547
&& new != * old
1548
1548
{
@@ -1553,17 +1553,17 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
1553
1553
} )
1554
1554
. collect :: < Vec < String > > ( )
1555
1555
} else {
1556
- fields. map ( |f| format ! ( "{f}{tail}" ) ) . collect :: < Vec < String > > ( )
1556
+ fields
1557
+ . iter ( )
1558
+ . map ( |f| format ! ( "{f}{tail}" ) )
1559
+ . collect :: < Vec < String > > ( )
1557
1560
} ;
1558
1561
1559
1562
( fields. join ( ", " ) , applicability)
1560
1563
}
1561
1564
None => ( "/* fields */" . to_string ( ) , Applicability :: HasPlaceholders ) ,
1562
1565
} ;
1563
- let pad = match field_ids {
1564
- Some ( [ ] ) => "" ,
1565
- _ => " " ,
1566
- } ;
1566
+ let pad = if has_fields { " " } else { "" } ;
1567
1567
err. span_suggestion (
1568
1568
span,
1569
1569
format ! ( "use struct {descr} syntax instead" ) ,
@@ -1723,12 +1723,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
1723
1723
& args[ ..] ,
1724
1724
) ;
1725
1725
// Use spans of the tuple struct definition.
1726
- self . r . field_def_ids ( def_id) . map ( |field_ids| {
1727
- field_ids
1728
- . iter ( )
1729
- . map ( |& field_id| self . r . def_span ( field_id) )
1730
- . collect :: < Vec < _ > > ( )
1731
- } )
1726
+ self . r
1727
+ . field_idents ( def_id)
1728
+ . map ( |fields| fields. iter ( ) . map ( |f| f. span ) . collect :: < Vec < _ > > ( ) )
1732
1729
}
1733
1730
_ => None ,
1734
1731
} ;
@@ -1791,7 +1788,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
1791
1788
( Res :: Def ( DefKind :: Ctor ( _, CtorKind :: Fn ) , ctor_def_id) , _) if ns == ValueNS => {
1792
1789
let def_id = self . r . tcx . parent ( ctor_def_id) ;
1793
1790
err. span_label ( self . r . def_span ( def_id) , format ! ( "`{path_str}` defined here" ) ) ;
1794
- let fields = self . r . field_def_ids ( def_id) . map_or_else (
1791
+ let fields = self . r . field_idents ( def_id) . map_or_else (
1795
1792
|| "/* fields */" . to_string ( ) ,
1796
1793
|field_ids| vec ! [ "_" ; field_ids. len( ) ] . join ( ", " ) ,
1797
1794
) ;
@@ -2017,12 +2014,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2017
2014
if let Some ( Res :: Def ( DefKind :: Struct | DefKind :: Union , did) ) =
2018
2015
resolution. full_res ( )
2019
2016
{
2020
- if let Some ( field_ids) = self . r . field_def_ids ( did) {
2021
- if let Some ( field_id) = field_ids
2022
- . iter ( )
2023
- . find ( |& & field_id| ident. name == self . r . tcx . item_name ( field_id) )
2024
- {
2025
- return Some ( AssocSuggestion :: Field ( self . r . def_span ( * field_id) ) ) ;
2017
+ if let Some ( fields) = self . r . field_idents ( did) {
2018
+ if let Some ( field) = fields. iter ( ) . find ( |id| ident. name == id. name ) {
2019
+ return Some ( AssocSuggestion :: Field ( field. span ) ) ;
2026
2020
}
2027
2021
}
2028
2022
}
@@ -2418,7 +2412,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2418
2412
match kind {
2419
2413
CtorKind :: Const => false ,
2420
2414
CtorKind :: Fn => {
2421
- !self . r . field_def_ids ( def_id) . is_some_and ( |field_ids| field_ids. is_empty ( ) )
2415
+ !self . r . field_idents ( def_id) . is_some_and ( |field_ids| field_ids. is_empty ( ) )
2422
2416
}
2423
2417
}
2424
2418
} ;
0 commit comments