@@ -1532,17 +1532,17 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
15321532                    if  !this. has_private_fields ( def_id)  { 
15331533                        // If the fields of the type are private, we shouldn't be suggesting using 
15341534                        // 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)  => { 
15401539                                let  fields = if  let  Some ( old_fields)  = old_fields { 
15411540                                    fields
1541+                                         . iter ( ) 
15421542                                        . enumerate ( ) 
15431543                                        . map ( |( idx,  new) | ( new,  old_fields. get ( idx) ) ) 
15441544                                        . map ( |( new,  old) | { 
1545-                                             let  new = new. to_ident_string ( ) ; 
1545+                                             let  new = new. name . to_ident_string ( ) ; 
15461546                                            if  let  Some ( Some ( old) )  = old
15471547                                                && new != * old
15481548                                            { 
@@ -1553,17 +1553,17 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
15531553                                        } ) 
15541554                                        . collect :: < Vec < String > > ( ) 
15551555                                }  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 > > ( ) 
15571560                                } ; 
15581561
15591562                                ( fields. join ( ", " ) ,  applicability) 
15601563                            } 
15611564                            None  => ( "/* fields */" . to_string ( ) ,  Applicability :: HasPlaceholders ) , 
15621565                        } ; 
1563-                         let  pad = match  field_ids { 
1564-                             Some ( [ ] )  => "" , 
1565-                             _ => " " , 
1566-                         } ; 
1566+                         let  pad = if  has_fields {  " "  }  else  {  ""  } ; 
15671567                        err. span_suggestion ( 
15681568                            span, 
15691569                            format ! ( "use struct {descr} syntax instead" ) , 
@@ -1723,12 +1723,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
17231723                            & args[ ..] , 
17241724                        ) ; 
17251725                        // 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 < _ > > ( ) ) 
17321729                    } 
17331730                    _ => None , 
17341731                } ; 
@@ -1791,7 +1788,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
17911788            ( Res :: Def ( DefKind :: Ctor ( _,  CtorKind :: Fn ) ,  ctor_def_id) ,  _)  if  ns == ValueNS  => { 
17921789                let  def_id = self . r . tcx . parent ( ctor_def_id) ; 
17931790                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 ( 
17951792                    || "/* fields */" . to_string ( ) , 
17961793                    |field_ids| vec ! [ "_" ;  field_ids. len( ) ] . join ( ", " ) , 
17971794                ) ; 
@@ -2017,12 +2014,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
20172014                    if  let  Some ( Res :: Def ( DefKind :: Struct  | DefKind :: Union ,  did) )  =
20182015                        resolution. full_res ( ) 
20192016                    { 
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 ) ) ; 
20262020                            } 
20272021                        } 
20282022                    } 
@@ -2418,7 +2412,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
24182412                match  kind { 
24192413                    CtorKind :: Const  => false , 
24202414                    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 ( ) ) 
24222416                    } 
24232417                } 
24242418            } ; 
0 commit comments