1
1
//! The Rust AST Visitor. Extracts useful information and massages it into a form
2
2
//! usable for `clean`.
3
3
4
- use rustc_data_structures:: fx:: FxHashSet ;
4
+ use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap } ;
5
5
use rustc_hir as hir;
6
6
use rustc_hir:: def:: { DefKind , Res } ;
7
7
use rustc_hir:: def_id:: { DefId , DefIdMap , LocalDefId , LocalDefIdSet } ;
@@ -26,8 +26,12 @@ pub(crate) struct Module<'hir> {
26
26
pub ( crate ) where_inner : Span ,
27
27
pub ( crate ) mods : Vec < Module < ' hir > > ,
28
28
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
+ > ,
31
35
pub ( crate ) foreigns : Vec < ( & ' hir hir:: ForeignItem < ' hir > , Option < Symbol > ) > ,
32
36
}
33
37
@@ -38,7 +42,7 @@ impl Module<'_> {
38
42
def_id,
39
43
where_inner,
40
44
mods : Vec :: new ( ) ,
41
- items : Vec :: new ( ) ,
45
+ items : FxIndexMap :: default ( ) ,
42
46
foreigns : Vec :: new ( ) ,
43
47
}
44
48
}
@@ -136,7 +140,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
136
140
inserted. insert ( def_id)
137
141
{
138
142
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 ) ) ;
140
144
}
141
145
}
142
146
@@ -294,7 +298,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
294
298
renamed : Option < Symbol > ,
295
299
parent_id : Option < LocalDefId > ,
296
300
) {
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) ) ;
298
306
}
299
307
300
308
fn visit_item_inner (
0 commit comments