@@ -18,7 +18,7 @@ use rustc_ast::ptr::P;
1818use rustc_ast_pretty:: pprust:: { self , PrintState , item_to_string} ;
1919use rustc_span:: symbol:: { Ident , kw} ;
2020use rustc_data_structures:: map_in_place:: MapInPlace ;
21- use rustc_span:: { BytePos , DUMMY_SP } ;
21+ use rustc_span:: { BytePos , DUMMY_SP , Symbol } ;
2222use smallvec:: smallvec;
2323
2424use crate :: ast_manip:: util:: { is_relative_path, join_visibility, namespace, split_uses, is_exported, is_c2rust_attr} ;
@@ -28,7 +28,6 @@ use crate::driver::Phase;
2828use crate :: { expect, match_or} ;
2929use crate :: path_edit:: fold_resolved_paths_with_id;
3030use crate :: RefactorCtxt ;
31- use crate :: util:: Lone ;
3231use crate :: ast_builder:: mk;
3332
3433use super :: externs;
@@ -553,10 +552,20 @@ impl<'a, 'tcx> Reorganizer<'a, 'tcx> {
553552 let mut module_items: IndexMap < NodeId , Vec < MovedDecl > > = IndexMap :: new ( ) ;
554553 // Move named items into module_items
555554 idents. map ( |idents| {
556- for ( ident, items) in idents. into_iter ( ) {
557- for item in items {
555+ for items in idents. into_values ( ) {
556+ for ( idx, mut item) in items. into_iter ( ) . enumerate ( ) {
557+ if idx > 0 {
558+ let ident = item. ident ( ) ;
559+ // Append a number suffix to this item if
560+ // there are multiple items with the same name
561+ let name = ident. name . as_str ( ) ;
562+ let name = format ! ( "{name}_{idx}" ) ;
563+ item. ident_mut ( ) . name = Symbol :: intern ( & name) ;
564+ }
565+
558566 let dest_module_id = self . find_destination_id ( & item) ;
559567
568+ let ident = item. ident ( ) ;
560569 let dest_module_info = self . modules . get_mut ( & dest_module_id) . unwrap ( ) ;
561570 dest_module_info. items [ item. namespace ] . insert ( ident) ;
562571 let mut path_segments = dest_module_info. path . clone ( ) ;
@@ -1100,6 +1109,22 @@ impl MovedDecl {
11001109 } ,
11011110 }
11021111 }
1112+
1113+ fn ident_mut ( & mut self ) -> & mut Ident {
1114+ match & mut self . kind {
1115+ DeclKind :: ForeignItem ( item, _) => & mut item. ident ,
1116+ DeclKind :: Item ( item) => {
1117+ // Reborrow the item inside the P<Item> so we can
1118+ // sub-borrow different fields from it
1119+ let item = & mut * * item;
1120+ if let ItemKind :: Use ( UseTree { kind : UseTreeKind :: Simple ( Some ( rename) , _, _) , .. } ) = & mut item. kind {
1121+ rename
1122+ } else {
1123+ & mut item. ident
1124+ }
1125+ }
1126+ }
1127+ }
11031128}
11041129
11051130impl ToString for MovedDecl {
@@ -1408,8 +1433,8 @@ impl<'a, 'tcx> HeaderDeclarations<'a, 'tcx> {
14081433 . type_ns
14091434 . into_iter ( )
14101435 . chain ( unnamed_items. value_ns . into_iter ( ) )
1411- . chain ( idents. type_ns . into_iter ( ) . map ( | ( _ , v ) | v . lone ( ) ) )
1412- . chain ( idents. value_ns . into_iter ( ) . map ( | ( _ , v ) | v . lone ( ) ) )
1436+ . chain ( idents. type_ns . into_values ( ) . flatten ( ) )
1437+ . chain ( idents. value_ns . into_values ( ) . flatten ( ) )
14131438 . collect :: < Vec < _ > > ( ) ;
14141439
14151440 all_items. sort_by ( |a, b| {
0 commit comments