Skip to content

Commit 488d5b0

Browse files
committed
rustdoc-search: add type param names to index
1 parent 298c746 commit 488d5b0

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

Diff for: src/librustdoc/html/render/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ pub(crate) struct IndexItemFunctionType {
204204
inputs: Vec<RenderType>,
205205
output: Vec<RenderType>,
206206
where_clause: Vec<Vec<RenderType>>,
207+
param_names: Vec<Symbol>,
207208
}
208209

209210
impl IndexItemFunctionType {

Diff for: src/librustdoc/html/render/search_index.rs

+38-7
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,25 @@ pub(crate) fn build_index<'tcx>(
646646
full_paths.push((*index, path));
647647
}
648648

649+
let param_names: Vec<(usize, String)> = {
650+
let mut prev = Vec::new();
651+
let mut result = Vec::new();
652+
for (index, item) in self.items.iter().enumerate() {
653+
if let Some(ty) = &item.search_type
654+
&& let my =
655+
ty.param_names.iter().map(|sym| sym.as_str()).collect::<Vec<_>>()
656+
&& my != prev
657+
{
658+
result.push((index, my.join(",")));
659+
prev = my;
660+
}
661+
}
662+
result
663+
};
664+
649665
let has_aliases = !self.aliases.is_empty();
650666
let mut crate_data =
651-
serializer.serialize_struct("CrateData", if has_aliases { 9 } else { 8 })?;
667+
serializer.serialize_struct("CrateData", if has_aliases { 13 } else { 12 })?;
652668
crate_data.serialize_field("t", &types)?;
653669
crate_data.serialize_field("n", &names)?;
654670
crate_data.serialize_field("q", &full_paths)?;
@@ -660,6 +676,7 @@ pub(crate) fn build_index<'tcx>(
660676
crate_data.serialize_field("b", &self.associated_item_disambiguators)?;
661677
crate_data.serialize_field("c", &bitmap_to_string(&deprecated))?;
662678
crate_data.serialize_field("e", &bitmap_to_string(&self.empty_desc))?;
679+
crate_data.serialize_field("P", &param_names)?;
663680
if has_aliases {
664681
crate_data.serialize_field("a", &self.aliases)?;
665682
}
@@ -758,7 +775,7 @@ pub(crate) fn get_function_type_for_search<'tcx>(
758775
None
759776
}
760777
});
761-
let (mut inputs, mut output, where_clause) = match item.kind {
778+
let (mut inputs, mut output, param_names, where_clause) = match item.kind {
762779
clean::ForeignFunctionItem(ref f, _)
763780
| clean::FunctionItem(ref f)
764781
| clean::MethodItem(ref f, _)
@@ -771,7 +788,7 @@ pub(crate) fn get_function_type_for_search<'tcx>(
771788
inputs.retain(|a| a.id.is_some() || a.generics.is_some());
772789
output.retain(|a| a.id.is_some() || a.generics.is_some());
773790

774-
Some(IndexItemFunctionType { inputs, output, where_clause })
791+
Some(IndexItemFunctionType { inputs, output, where_clause, param_names })
775792
}
776793

777794
fn get_index_type(
@@ -1285,7 +1302,7 @@ fn get_fn_inputs_and_outputs<'tcx>(
12851302
tcx: TyCtxt<'tcx>,
12861303
impl_or_trait_generics: Option<&(clean::Type, clean::Generics)>,
12871304
cache: &Cache,
1288-
) -> (Vec<RenderType>, Vec<RenderType>, Vec<Vec<RenderType>>) {
1305+
) -> (Vec<RenderType>, Vec<RenderType>, Vec<Symbol>, Vec<Vec<RenderType>>) {
12891306
let decl = &func.decl;
12901307

12911308
let mut rgen: FxIndexMap<SimplifiedParam, (isize, Vec<RenderType>)> = Default::default();
@@ -1331,7 +1348,21 @@ fn get_fn_inputs_and_outputs<'tcx>(
13311348
let mut ret_types = Vec::new();
13321349
simplify_fn_type(self_, generics, &decl.output, tcx, 0, &mut ret_types, &mut rgen, true, cache);
13331350

1334-
let mut simplified_params = rgen.into_values().collect::<Vec<_>>();
1335-
simplified_params.sort_by_key(|(idx, _)| -idx);
1336-
(arg_types, ret_types, simplified_params.into_iter().map(|(_idx, traits)| traits).collect())
1351+
let mut simplified_params = rgen.into_iter().collect::<Vec<_>>();
1352+
simplified_params.sort_by_key(|(_, (idx, _))| -idx);
1353+
(
1354+
arg_types,
1355+
ret_types,
1356+
simplified_params
1357+
.iter()
1358+
.map(|(name, (_idx, _traits))| match name {
1359+
SimplifiedParam::Symbol(name) => *name,
1360+
SimplifiedParam::Anonymous(_) => kw::Empty,
1361+
SimplifiedParam::AssociatedType(def_id, name) => {
1362+
Symbol::intern(&format!("{}::{}", tcx.item_name(*def_id), name))
1363+
}
1364+
})
1365+
.collect(),
1366+
simplified_params.into_iter().map(|(_name, (_idx, traits))| traits).collect(),
1367+
)
13371368
}

0 commit comments

Comments
 (0)