Skip to content

Commit 5c8e8e5

Browse files
committed
Give clearer names to several search index functions
1 parent afb77a9 commit 5c8e8e5

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

src/librustdoc/formats/cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::fold::DocFolder;
1212
use crate::formats::item_type::ItemType;
1313
use crate::formats::Impl;
1414
use crate::html::markdown::short_markdown_summary;
15-
use crate::html::render::search_index::get_index_search_type;
15+
use crate::html::render::search_index::get_function_type_for_search;
1616
use crate::html::render::IndexItem;
1717

1818
/// This cache is used to store information about the [`clean::Crate`] being
@@ -303,7 +303,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
303303
desc,
304304
parent,
305305
parent_idx: None,
306-
search_type: get_index_search_type(&item, self.tcx),
306+
search_type: get_function_type_for_search(&item, self.tcx),
307307
aliases: item.attrs.get_doc_aliases(),
308308
});
309309
}

src/librustdoc/html/render/search_index.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
3232
desc,
3333
parent: Some(did),
3434
parent_idx: None,
35-
search_type: get_index_search_type(item, tcx),
35+
search_type: get_function_type_for_search(item, tcx),
3636
aliases: item.attrs.get_doc_aliases(),
3737
});
3838
}
@@ -181,14 +181,14 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
181181
)
182182
}
183183

184-
crate fn get_index_search_type<'tcx>(
184+
crate fn get_function_type_for_search<'tcx>(
185185
item: &clean::Item,
186186
tcx: TyCtxt<'tcx>,
187187
) -> Option<IndexItemFunctionType> {
188188
let (mut inputs, mut output) = match *item.kind {
189-
clean::FunctionItem(ref f) => get_all_types(f, tcx),
190-
clean::MethodItem(ref m, _) => get_all_types(m, tcx),
191-
clean::TyMethodItem(ref m) => get_all_types(m, tcx),
189+
clean::FunctionItem(ref f) => get_fn_inputs_and_outputs(f, tcx),
190+
clean::MethodItem(ref m, _) => get_fn_inputs_and_outputs(m, tcx),
191+
clean::TyMethodItem(ref m) => get_fn_inputs_and_outputs(m, tcx),
192192
_ => return None,
193193
};
194194

@@ -237,7 +237,7 @@ fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option
237237
///
238238
/// Important note: It goes through generics recursively. So if you have
239239
/// `T: Option<Result<(), ()>>`, it'll go into `Option` and then into `Result`.
240-
fn get_real_types<'tcx>(
240+
fn add_generics_and_bounds_as_types<'tcx>(
241241
generics: &Generics,
242242
arg: &Type,
243243
tcx: TyCtxt<'tcx>,
@@ -337,7 +337,13 @@ fn get_real_types<'tcx>(
337337
for param_def in poly_trait.generic_params.iter() {
338338
match &param_def.kind {
339339
clean::GenericParamDefKind::Type { default: Some(ty), .. } => {
340-
get_real_types(generics, ty, tcx, recurse + 1, &mut ty_generics)
340+
add_generics_and_bounds_as_types(
341+
generics,
342+
ty,
343+
tcx,
344+
recurse + 1,
345+
&mut ty_generics,
346+
)
341347
}
342348
_ => {}
343349
}
@@ -352,7 +358,13 @@ fn get_real_types<'tcx>(
352358
for bound in bound.get_bounds().unwrap_or(&[]) {
353359
if let Some(path) = bound.get_trait_path() {
354360
let ty = Type::Path { path };
355-
get_real_types(generics, &ty, tcx, recurse + 1, &mut ty_generics);
361+
add_generics_and_bounds_as_types(
362+
generics,
363+
&ty,
364+
tcx,
365+
recurse + 1,
366+
&mut ty_generics,
367+
);
356368
}
357369
}
358370
insert_ty(res, tcx, arg.clone(), ty_generics);
@@ -366,7 +378,7 @@ fn get_real_types<'tcx>(
366378
let mut ty_generics = Vec::new();
367379
if let Some(arg_generics) = arg.generics() {
368380
for gen in arg_generics.iter() {
369-
get_real_types(generics, gen, tcx, recurse + 1, &mut ty_generics);
381+
add_generics_and_bounds_as_types(generics, gen, tcx, recurse + 1, &mut ty_generics);
370382
}
371383
}
372384
insert_ty(res, tcx, arg.clone(), ty_generics);
@@ -377,7 +389,7 @@ fn get_real_types<'tcx>(
377389
///
378390
/// i.e. `fn foo<A: Display, B: Option<A>>(x: u32, y: B)` will return
379391
/// `[u32, Display, Option]`.
380-
fn get_all_types<'tcx>(
392+
fn get_fn_inputs_and_outputs<'tcx>(
381393
func: &Function,
382394
tcx: TyCtxt<'tcx>,
383395
) -> (Vec<TypeWithKind>, Vec<TypeWithKind>) {
@@ -390,7 +402,7 @@ fn get_all_types<'tcx>(
390402
continue;
391403
}
392404
let mut args = Vec::new();
393-
get_real_types(generics, &arg.type_, tcx, 0, &mut args);
405+
add_generics_and_bounds_as_types(generics, &arg.type_, tcx, 0, &mut args);
394406
if !args.is_empty() {
395407
all_types.extend(args);
396408
} else {
@@ -404,7 +416,7 @@ fn get_all_types<'tcx>(
404416
let mut ret_types = Vec::new();
405417
match decl.output {
406418
FnRetTy::Return(ref return_type) => {
407-
get_real_types(generics, return_type, tcx, 0, &mut ret_types);
419+
add_generics_and_bounds_as_types(generics, return_type, tcx, 0, &mut ret_types);
408420
if ret_types.is_empty() {
409421
if let Some(kind) =
410422
return_type.def_id_no_primitives().map(|did| tcx.def_kind(did).into())

0 commit comments

Comments
 (0)