Skip to content

Commit 5deb396

Browse files
committed
Fix rustdoc under #[no_core]
1 parent dc1fc08 commit 5deb396

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

src/librustdoc/html/render/search_index.rs

+32-28
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ use std::collections::BTreeMap;
33

44
use rustc_data_structures::fx::FxHashMap;
55
use rustc_middle::ty::TyCtxt;
6-
use rustc_span::def_id::DefId;
6+
use rustc_span::def_id::LOCAL_CRATE;
77
use rustc_span::symbol::Symbol;
88
use serde::ser::{Serialize, SerializeStruct, Serializer};
99

1010
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+
};
1214
use crate::formats::cache::{Cache, OrphanImplItem};
1315
use crate::formats::item_type::ItemType;
1416
use crate::html::format::join_with_double_colon;
@@ -21,7 +23,7 @@ pub(crate) fn build_index<'tcx>(
2123
cache: &mut Cache,
2224
tcx: TyCtxt<'tcx>,
2325
) -> String {
24-
let mut defid_to_pathid = FxHashMap::default();
26+
let mut itemid_to_pathid = FxHashMap::default();
2527
let mut crate_paths = vec![];
2628

2729
// Attach all orphan items to the type's definition if the type
@@ -79,38 +81,39 @@ pub(crate) fn build_index<'tcx>(
7981
fn convert_render_type(
8082
ty: &mut RenderType,
8183
cache: &mut Cache,
82-
defid_to_pathid: &mut FxHashMap<DefId, usize>,
84+
itemid_to_pathid: &mut FxHashMap<ItemId, usize>,
8385
lastpathid: &mut usize,
8486
crate_paths: &mut Vec<(ItemType, Symbol)>,
8587
) {
8688
if let Some(generics) = &mut ty.generics {
8789
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);
8991
}
9092
}
9193
let Cache { ref paths, ref external_paths, .. } = *cache;
9294
let Some(id) = ty.id.clone() else {
9395
assert!(ty.generics.is_some());
9496
return;
9597
};
96-
let (defid, path, item_type) = match id {
98+
let (itemid, path, item_type) = match id {
9799
RenderTypeId::DefId(defid) => {
98100
if let Some(&(ref fqp, item_type)) =
99101
paths.get(&defid).or_else(|| external_paths.get(&defid))
100102
{
101-
(defid, *fqp.last().unwrap(), item_type)
103+
(ItemId::DefId(defid), *fqp.last().unwrap(), item_type)
102104
} else {
103105
ty.id = None;
104106
return;
105107
}
106108
}
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+
),
111114
RenderTypeId::Index(_) => return,
112115
};
113-
match defid_to_pathid.entry(defid) {
116+
match itemid_to_pathid.entry(itemid) {
114117
Entry::Occupied(entry) => ty.id = Some(RenderTypeId::Index(*entry.get())),
115118
Entry::Vacant(entry) => {
116119
let pathid = *lastpathid;
@@ -126,7 +129,7 @@ pub(crate) fn build_index<'tcx>(
126129
convert_render_type(
127130
item,
128131
cache,
129-
&mut defid_to_pathid,
132+
&mut itemid_to_pathid,
130133
&mut lastpathid,
131134
&mut crate_paths,
132135
);
@@ -135,7 +138,7 @@ pub(crate) fn build_index<'tcx>(
135138
convert_render_type(
136139
item,
137140
cache,
138-
&mut defid_to_pathid,
141+
&mut itemid_to_pathid,
139142
&mut lastpathid,
140143
&mut crate_paths,
141144
);
@@ -149,21 +152,22 @@ pub(crate) fn build_index<'tcx>(
149152
let crate_items: Vec<&IndexItem> = search_index
150153
.iter_mut()
151154
.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+
}
164169
}
165-
}
166-
});
170+
});
167171

168172
// Omit the parent path if it is same to that of the prior item.
169173
if lastpath == &item.path {

0 commit comments

Comments
 (0)