@@ -3,7 +3,6 @@ use std::collections::BTreeMap;
3
3
4
4
use rustc_data_structures:: fx:: FxHashMap ;
5
5
use rustc_middle:: ty:: TyCtxt ;
6
- use rustc_span:: def_id:: LOCAL_CRATE ;
7
6
use rustc_span:: symbol:: Symbol ;
8
7
use serde:: ser:: { Serialize , SerializeStruct , Serializer } ;
9
8
@@ -24,6 +23,7 @@ pub(crate) fn build_index<'tcx>(
24
23
tcx : TyCtxt < ' tcx > ,
25
24
) -> String {
26
25
let mut itemid_to_pathid = FxHashMap :: default ( ) ;
26
+ let mut primitives = FxHashMap :: default ( ) ;
27
27
let mut crate_paths = vec ! [ ] ;
28
28
29
29
// Attach all orphan items to the type's definition if the type
@@ -78,50 +78,83 @@ pub(crate) fn build_index<'tcx>(
78
78
// First, on function signatures
79
79
let mut search_index = std:: mem:: replace ( & mut cache. search_index , Vec :: new ( ) ) ;
80
80
for item in search_index. iter_mut ( ) {
81
+ fn insert_into_map < F : std:: hash:: Hash + Eq > (
82
+ ty : & mut RenderType ,
83
+ map : & mut FxHashMap < F , usize > ,
84
+ itemid : F ,
85
+ lastpathid : & mut usize ,
86
+ crate_paths : & mut Vec < ( ItemType , Symbol ) > ,
87
+ item_type : ItemType ,
88
+ path : Symbol ,
89
+ ) {
90
+ match map. entry ( itemid) {
91
+ Entry :: Occupied ( entry) => ty. id = Some ( RenderTypeId :: Index ( * entry. get ( ) ) ) ,
92
+ Entry :: Vacant ( entry) => {
93
+ let pathid = * lastpathid;
94
+ entry. insert ( pathid) ;
95
+ * lastpathid += 1 ;
96
+ crate_paths. push ( ( item_type, path) ) ;
97
+ ty. id = Some ( RenderTypeId :: Index ( pathid) ) ;
98
+ }
99
+ }
100
+ }
101
+
81
102
fn convert_render_type (
82
103
ty : & mut RenderType ,
83
104
cache : & mut Cache ,
84
105
itemid_to_pathid : & mut FxHashMap < ItemId , usize > ,
106
+ primitives : & mut FxHashMap < Symbol , usize > ,
85
107
lastpathid : & mut usize ,
86
108
crate_paths : & mut Vec < ( ItemType , Symbol ) > ,
87
109
) {
88
110
if let Some ( generics) = & mut ty. generics {
89
111
for item in generics {
90
- convert_render_type ( item, cache, itemid_to_pathid, lastpathid, crate_paths) ;
112
+ convert_render_type (
113
+ item,
114
+ cache,
115
+ itemid_to_pathid,
116
+ primitives,
117
+ lastpathid,
118
+ crate_paths,
119
+ ) ;
91
120
}
92
121
}
93
122
let Cache { ref paths, ref external_paths, .. } = * cache;
94
123
let Some ( id) = ty. id . clone ( ) else {
95
124
assert ! ( ty. generics. is_some( ) ) ;
96
125
return ;
97
126
} ;
98
- let ( itemid , path , item_type ) = match id {
127
+ match id {
99
128
RenderTypeId :: DefId ( defid) => {
100
129
if let Some ( & ( ref fqp, item_type) ) =
101
130
paths. get ( & defid) . or_else ( || external_paths. get ( & defid) )
102
131
{
103
- ( ItemId :: DefId ( defid) , * fqp. last ( ) . unwrap ( ) , item_type)
132
+ insert_into_map (
133
+ ty,
134
+ itemid_to_pathid,
135
+ ItemId :: DefId ( defid) ,
136
+ lastpathid,
137
+ crate_paths,
138
+ item_type,
139
+ * fqp. last ( ) . unwrap ( ) ,
140
+ ) ;
104
141
} else {
105
142
ty. id = None ;
106
- return ;
107
143
}
108
144
}
109
- RenderTypeId :: Primitive ( primitive) => (
110
- ItemId :: Primitive ( primitive, LOCAL_CRATE ) ,
111
- primitive. as_sym ( ) ,
112
- ItemType :: Primitive ,
113
- ) ,
114
- RenderTypeId :: Index ( _) => return ,
115
- } ;
116
- match itemid_to_pathid. entry ( itemid) {
117
- Entry :: Occupied ( entry) => ty. id = Some ( RenderTypeId :: Index ( * entry. get ( ) ) ) ,
118
- Entry :: Vacant ( entry) => {
119
- let pathid = * lastpathid;
120
- entry. insert ( pathid) ;
121
- * lastpathid += 1 ;
122
- crate_paths. push ( ( item_type, path) ) ;
123
- ty. id = Some ( RenderTypeId :: Index ( pathid) ) ;
145
+ RenderTypeId :: Primitive ( primitive) => {
146
+ let sym = primitive. as_sym ( ) ;
147
+ insert_into_map (
148
+ ty,
149
+ primitives,
150
+ sym,
151
+ lastpathid,
152
+ crate_paths,
153
+ ItemType :: Primitive ,
154
+ sym,
155
+ ) ;
124
156
}
157
+ RenderTypeId :: Index ( _) => { }
125
158
}
126
159
}
127
160
if let Some ( search_type) = & mut item. search_type {
@@ -130,6 +163,7 @@ pub(crate) fn build_index<'tcx>(
130
163
item,
131
164
cache,
132
165
& mut itemid_to_pathid,
166
+ & mut primitives,
133
167
& mut lastpathid,
134
168
& mut crate_paths,
135
169
) ;
@@ -139,6 +173,7 @@ pub(crate) fn build_index<'tcx>(
139
173
item,
140
174
cache,
141
175
& mut itemid_to_pathid,
176
+ & mut primitives,
142
177
& mut lastpathid,
143
178
& mut crate_paths,
144
179
) ;
0 commit comments