Skip to content

Commit b31f019

Browse files
authored
Rollup merge of rust-lang#90727 - GuillaumeGomez:remove-potential-useless-search-index-data, r=notriddle,camelid
Remove potential useless data for search index I uncovered this case when working on rust-lang#90726 to debug rust-lang#90385. Explanations: if we have a full generic, we check if it has generics then we do the following: * If it has only one generic, we remove one nested level in order to not keep the "parent" generic (since it has empty name, it's useless after all). * Otherwise we add it alongside its generics. However, I didn't handle the case where a generic had no generics. Meaning that we were adding items with empty names in the search index. So basically useless data in the search index. r? `@camelid`
2 parents 858fea4 + 8d5ef32 commit b31f019

File tree

1 file changed

+46
-39
lines changed

1 file changed

+46
-39
lines changed

src/librustdoc/html/render/cache.rs

+46-39
Original file line numberDiff line numberDiff line change
@@ -258,45 +258,52 @@ crate fn get_real_types<'tcx>(
258258
) {
259259
let is_full_generic = ty.is_full_generic();
260260

261-
if is_full_generic && generics.len() == 1 {
262-
// In this case, no need to go through an intermediate state if the generics
263-
// contains only one element.
264-
//
265-
// For example:
266-
//
267-
// fn foo<T: Display>(r: Option<T>) {}
268-
//
269-
// In this case, it would contain:
270-
//
271-
// ```
272-
// [{
273-
// name: "option",
274-
// generics: [{
275-
// name: "",
276-
// generics: [
277-
// name: "Display",
278-
// generics: []
279-
// }]
280-
// }]
281-
// }]
282-
// ```
283-
//
284-
// After removing the intermediate (unnecessary) full generic, it'll become:
285-
//
286-
// ```
287-
// [{
288-
// name: "option",
289-
// generics: [{
290-
// name: "Display",
291-
// generics: []
292-
// }]
293-
// }]
294-
// ```
295-
//
296-
// To be noted that it can work if there is ONLY ONE generic, otherwise we still
297-
// need to keep it as is!
298-
res.push(generics.pop().unwrap());
299-
return;
261+
if is_full_generic {
262+
if generics.is_empty() {
263+
// This is a type parameter with no trait bounds (for example: `T` in
264+
// `fn f<T>(p: T)`, so not useful for the rustdoc search because we would end up
265+
// with an empty type with an empty name. Let's just discard it.
266+
return;
267+
} else if generics.len() == 1 {
268+
// In this case, no need to go through an intermediate state if the type parameter
269+
// contains only one trait bound.
270+
//
271+
// For example:
272+
//
273+
// `fn foo<T: Display>(r: Option<T>) {}`
274+
//
275+
// In this case, it would contain:
276+
//
277+
// ```
278+
// [{
279+
// name: "option",
280+
// generics: [{
281+
// name: "",
282+
// generics: [
283+
// name: "Display",
284+
// generics: []
285+
// }]
286+
// }]
287+
// }]
288+
// ```
289+
//
290+
// After removing the intermediate (unnecessary) type parameter, it'll become:
291+
//
292+
// ```
293+
// [{
294+
// name: "option",
295+
// generics: [{
296+
// name: "Display",
297+
// generics: []
298+
// }]
299+
// }]
300+
// ```
301+
//
302+
// To be noted that it can work if there is ONLY ONE trait bound, otherwise we still
303+
// need to keep it as is!
304+
res.push(generics.pop().unwrap());
305+
return;
306+
}
300307
}
301308
let mut index_ty = get_index_type(&ty, generics);
302309
if index_ty.name.as_ref().map(|s| s.is_empty()).unwrap_or(true) {

0 commit comments

Comments
 (0)