11//! The Rust AST Visitor. Extracts useful information and massages it into a form
22//! usable for `clean`.
33
4- use rustc_data_structures:: fx:: FxHashSet ;
4+ use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap } ;
55use rustc_hir as hir;
66use rustc_hir:: def:: { DefKind , Res } ;
77use rustc_hir:: def_id:: { DefId , DefIdMap , LocalDefId , LocalDefIdSet } ;
@@ -26,8 +26,12 @@ pub(crate) struct Module<'hir> {
2626 pub ( crate ) where_inner : Span ,
2727 pub ( crate ) mods : Vec < Module < ' hir > > ,
2828 pub ( crate ) def_id : LocalDefId ,
29- // (item, renamed, import_id)
30- pub ( crate ) items : Vec < ( & ' hir hir:: Item < ' hir > , Option < Symbol > , Option < LocalDefId > ) > ,
29+ /// The key is the item `ItemId` and the value is: (item, renamed, import_id).
30+ /// We use `FxIndexMap` to keep the insert order.
31+ pub ( crate ) items : FxIndexMap <
32+ ( LocalDefId , Option < Symbol > ) ,
33+ ( & ' hir hir:: Item < ' hir > , Option < Symbol > , Option < LocalDefId > ) ,
34+ > ,
3135 pub ( crate ) foreigns : Vec < ( & ' hir hir:: ForeignItem < ' hir > , Option < Symbol > ) > ,
3236}
3337
@@ -38,7 +42,7 @@ impl Module<'_> {
3842 def_id,
3943 where_inner,
4044 mods : Vec :: new ( ) ,
41- items : Vec :: new ( ) ,
45+ items : FxIndexMap :: default ( ) ,
4246 foreigns : Vec :: new ( ) ,
4347 }
4448 }
@@ -136,7 +140,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
136140 inserted. insert ( def_id)
137141 {
138142 let item = self . cx . tcx . hir ( ) . expect_item ( local_def_id) ;
139- top_level_module. items . push ( ( item, None , None ) ) ;
143+ top_level_module. items . insert ( ( local_def_id , Some ( item . ident . name ) ) , ( item, None , None ) ) ;
140144 }
141145 }
142146
@@ -294,7 +298,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
294298 renamed : Option < Symbol > ,
295299 parent_id : Option < LocalDefId > ,
296300 ) {
297- self . modules . last_mut ( ) . unwrap ( ) . items . push ( ( item, renamed, parent_id) )
301+ self . modules
302+ . last_mut ( )
303+ . unwrap ( )
304+ . items
305+ . insert ( ( item. owner_id . def_id , renamed) , ( item, renamed, parent_id) ) ;
298306 }
299307
300308 fn visit_item_inner (
0 commit comments