Skip to content

Commit 198e3ab

Browse files
Put back primitives in search
1 parent a2f8f62 commit 198e3ab

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

src/librustdoc/clean/types.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,7 @@ crate enum TypeKind {
13021302
Attr,
13031303
Derive,
13041304
TraitAlias,
1305+
Primitive,
13051306
}
13061307

13071308
crate trait GetDefId {
@@ -1404,6 +1405,16 @@ impl Type {
14041405
matches!(self, Type::Generic(_))
14051406
}
14061407

1408+
crate fn is_primitive(&self) -> bool {
1409+
match self {
1410+
Self::Primitive(_) => true,
1411+
Self::BorrowedRef { ref type_, .. } | Self::RawPointer(_, ref type_) => {
1412+
type_.is_primitive()
1413+
}
1414+
_ => false,
1415+
}
1416+
}
1417+
14071418
crate fn projection(&self) -> Option<(&Type, DefId, Symbol)> {
14081419
let (self_, trait_, name) = match self {
14091420
QPath { self_type, trait_, name } => (self_type, trait_, name),

src/librustdoc/clean/utils.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,20 @@ crate fn get_real_types(
171171
cx: &DocContext<'_>,
172172
recurse: i32,
173173
) -> FxHashSet<(Type, TypeKind)> {
174+
fn insert(res: &mut FxHashSet<(Type, TypeKind)>, cx: &DocContext<'_>, ty: Type) {
175+
if let Some(kind) = ty.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) {
176+
res.insert((ty, kind));
177+
} else if ty.is_primitive() {
178+
// This is a primitive, let's store it as such.
179+
res.insert((ty, TypeKind::Primitive));
180+
}
181+
}
174182
let mut res = FxHashSet::default();
175183
if recurse >= 10 {
176184
// FIXME: remove this whole recurse thing when the recursion bug is fixed
177185
return res;
178186
}
187+
179188
if arg.is_full_generic() {
180189
let arg_s = Symbol::intern(&arg.print(&cx.cache).to_string());
181190
if let Some(where_pred) = generics.where_predicates.iter().find(|g| match g {
@@ -194,11 +203,7 @@ crate fn get_real_types(
194203
if !adds.is_empty() {
195204
res.extend(adds);
196205
} else if !ty.is_full_generic() {
197-
if let Some(kind) =
198-
ty.def_id().map(|did| cx.tcx.def_kind(did).clean(cx))
199-
{
200-
res.insert((ty, kind));
201-
}
206+
insert(&mut res, cx, ty);
202207
}
203208
}
204209
}
@@ -212,26 +217,22 @@ crate fn get_real_types(
212217
if !adds.is_empty() {
213218
res.extend(adds);
214219
} else if !ty.is_full_generic() {
215-
if let Some(kind) = ty.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) {
216-
res.insert((ty.clone(), kind));
217-
}
220+
insert(&mut res, cx, ty);
218221
}
219222
}
220223
}
221224
}
222225
} else {
223-
if let Some(kind) = arg.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) {
224-
res.insert((arg.clone(), kind));
225-
}
226+
insert(&mut res, cx, arg.clone());
226227
if let Some(gens) = arg.generics() {
227228
for gen in gens.iter() {
228229
if gen.is_full_generic() {
229230
let adds = get_real_types(generics, gen, cx, recurse + 1);
230231
if !adds.is_empty() {
231232
res.extend(adds);
232233
}
233-
} else if let Some(kind) = gen.def_id().map(|did| cx.tcx.def_kind(did).clean(cx)) {
234-
res.insert((gen.clone(), kind));
234+
} else {
235+
insert(&mut res, cx, gen.clone());
235236
}
236237
}
237238
}

src/librustdoc/formats/item_type.rs

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ impl From<clean::TypeKind> for ItemType {
119119
clean::TypeKind::Attr => ItemType::ProcAttribute,
120120
clean::TypeKind::Derive => ItemType::ProcDerive,
121121
clean::TypeKind::TraitAlias => ItemType::TraitAlias,
122+
clean::TypeKind::Primitive => ItemType::Primitive,
122123
}
123124
}
124125
}

src/librustdoc/html/render/cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ crate fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
7878
desc: item.doc_value().map_or_else(String::new, |s| short_markdown_summary(&s)),
7979
parent: Some(did),
8080
parent_idx: None,
81-
search_type: get_index_search_type(&item, None),
81+
search_type: get_index_search_type(&item, Some(cache)),
8282
});
8383
for alias in item.attrs.get_doc_aliases() {
8484
cache

0 commit comments

Comments
 (0)