@@ -3,12 +3,14 @@ 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:: DefId ;
6
+ use rustc_span:: def_id:: LOCAL_CRATE ;
7
7
use rustc_span:: symbol:: Symbol ;
8
8
use serde:: ser:: { Serialize , SerializeStruct , Serializer } ;
9
9
10
10
use crate :: clean;
11
- use crate :: clean:: types:: { FnRetTy , Function , GenericBound , Generics , Type , WherePredicate } ;
11
+ use crate :: clean:: types:: {
12
+ FnRetTy , Function , GenericBound , Generics , ItemId , Type , WherePredicate ,
13
+ } ;
12
14
use crate :: formats:: cache:: { Cache , OrphanImplItem } ;
13
15
use crate :: formats:: item_type:: ItemType ;
14
16
use crate :: html:: format:: join_with_double_colon;
@@ -21,7 +23,7 @@ pub(crate) fn build_index<'tcx>(
21
23
cache : & mut Cache ,
22
24
tcx : TyCtxt < ' tcx > ,
23
25
) -> String {
24
- let mut defid_to_pathid = FxHashMap :: default ( ) ;
26
+ let mut itemid_to_pathid = FxHashMap :: default ( ) ;
25
27
let mut crate_paths = vec ! [ ] ;
26
28
27
29
// Attach all orphan items to the type's definition if the type
@@ -79,38 +81,39 @@ pub(crate) fn build_index<'tcx>(
79
81
fn convert_render_type (
80
82
ty : & mut RenderType ,
81
83
cache : & mut Cache ,
82
- defid_to_pathid : & mut FxHashMap < DefId , usize > ,
84
+ itemid_to_pathid : & mut FxHashMap < ItemId , usize > ,
83
85
lastpathid : & mut usize ,
84
86
crate_paths : & mut Vec < ( ItemType , Symbol ) > ,
85
87
) {
86
88
if let Some ( generics) = & mut ty. generics {
87
89
for item in generics {
88
- convert_render_type ( item, cache, defid_to_pathid , lastpathid, crate_paths) ;
90
+ convert_render_type ( item, cache, itemid_to_pathid , lastpathid, crate_paths) ;
89
91
}
90
92
}
91
93
let Cache { ref paths, ref external_paths, .. } = * cache;
92
94
let Some ( id) = ty. id . clone ( ) else {
93
95
assert ! ( ty. generics. is_some( ) ) ;
94
96
return ;
95
97
} ;
96
- let ( defid , path, item_type) = match id {
98
+ let ( itemid , path, item_type) = match id {
97
99
RenderTypeId :: DefId ( defid) => {
98
100
if let Some ( & ( ref fqp, item_type) ) =
99
101
paths. get ( & defid) . or_else ( || external_paths. get ( & defid) )
100
102
{
101
- ( defid, * fqp. last ( ) . unwrap ( ) , item_type)
103
+ ( ItemId :: DefId ( defid) , * fqp. last ( ) . unwrap ( ) , item_type)
102
104
} else {
103
105
ty. id = None ;
104
106
return ;
105
107
}
106
108
}
107
- RenderTypeId :: Primitive ( primitive) => {
108
- let defid = * cache. primitive_locations . get ( & primitive) . unwrap ( ) ;
109
- ( defid, primitive. as_sym ( ) , ItemType :: Primitive )
110
- }
109
+ RenderTypeId :: Primitive ( primitive) => (
110
+ ItemId :: Primitive ( primitive, LOCAL_CRATE ) ,
111
+ primitive. as_sym ( ) ,
112
+ ItemType :: Primitive ,
113
+ ) ,
111
114
RenderTypeId :: Index ( _) => return ,
112
115
} ;
113
- match defid_to_pathid . entry ( defid ) {
116
+ match itemid_to_pathid . entry ( itemid ) {
114
117
Entry :: Occupied ( entry) => ty. id = Some ( RenderTypeId :: Index ( * entry. get ( ) ) ) ,
115
118
Entry :: Vacant ( entry) => {
116
119
let pathid = * lastpathid;
@@ -126,7 +129,7 @@ pub(crate) fn build_index<'tcx>(
126
129
convert_render_type (
127
130
item,
128
131
cache,
129
- & mut defid_to_pathid ,
132
+ & mut itemid_to_pathid ,
130
133
& mut lastpathid,
131
134
& mut crate_paths,
132
135
) ;
@@ -135,7 +138,7 @@ pub(crate) fn build_index<'tcx>(
135
138
convert_render_type (
136
139
item,
137
140
cache,
138
- & mut defid_to_pathid ,
141
+ & mut itemid_to_pathid ,
139
142
& mut lastpathid,
140
143
& mut crate_paths,
141
144
) ;
@@ -149,21 +152,22 @@ pub(crate) fn build_index<'tcx>(
149
152
let crate_items: Vec < & IndexItem > = search_index
150
153
. iter_mut ( )
151
154
. map ( |item| {
152
- item. parent_idx = item. parent . and_then ( |defid| match defid_to_pathid. entry ( defid) {
153
- Entry :: Occupied ( entry) => Some ( * entry. get ( ) ) ,
154
- Entry :: Vacant ( entry) => {
155
- let pathid = lastpathid;
156
- entry. insert ( pathid) ;
157
- lastpathid += 1 ;
158
-
159
- if let Some ( & ( ref fqp, short) ) = paths. get ( & defid) {
160
- crate_paths. push ( ( short, * fqp. last ( ) . unwrap ( ) ) ) ;
161
- Some ( pathid)
162
- } else {
163
- None
155
+ item. parent_idx =
156
+ item. parent . and_then ( |defid| match itemid_to_pathid. entry ( ItemId :: DefId ( defid) ) {
157
+ Entry :: Occupied ( entry) => Some ( * entry. get ( ) ) ,
158
+ Entry :: Vacant ( entry) => {
159
+ let pathid = lastpathid;
160
+ entry. insert ( pathid) ;
161
+ lastpathid += 1 ;
162
+
163
+ if let Some ( & ( ref fqp, short) ) = paths. get ( & defid) {
164
+ crate_paths. push ( ( short, * fqp. last ( ) . unwrap ( ) ) ) ;
165
+ Some ( pathid)
166
+ } else {
167
+ None
168
+ }
164
169
}
165
- }
166
- } ) ;
170
+ } ) ;
167
171
168
172
// Omit the parent path if it is same to that of the prior item.
169
173
if lastpath == & item. path {
0 commit comments