Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 9 additions & 25 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ use crate::core::DocContext;
use crate::fold::DocFolder;
use crate::formats::Impl;
use crate::formats::item_type::ItemType;
use crate::html::markdown::short_markdown_summary;
use crate::html::render::IndexItem;
use crate::html::render::search_index::get_function_type_for_search;
use crate::visit_lib::RustdocEffectiveVisibilities;

/// This cache is used to store information about the [`clean::Crate`] being
Expand Down Expand Up @@ -574,7 +572,6 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It

debug_assert!(!item.is_stripped());

let desc = short_markdown_summary(&item.doc_value(), &item.link_names(cache));
// For searching purposes, a re-export is a duplicate if:
//
// - It's either an inline, or a true re-export
Expand All @@ -585,31 +582,18 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
_ => item_def_id,
};
let (impl_id, trait_parent) = cache.parent_stack_last_impl_and_trait_id();
let search_type = get_function_type_for_search(
item,
let index_item = IndexItem::new(
tcx,
clean_impl_generics(cache.parent_stack.last()).as_ref(),
parent_did,
cache,
);
let aliases = item.attrs.get_doc_aliases();
let deprecation = item.deprecation(tcx);
let index_item = IndexItem {
ty: item.type_(),
defid: Some(defid),
name,
module_path: parent_path.to_vec(),
desc,
parent: parent_did,
parent_idx: None,
trait_parent,
trait_parent_idx: None,
exact_module_path: None,
item,
Some(name),
Some(defid),
parent_path.to_vec(),
parent_did,
impl_id,
search_type,
aliases,
deprecation,
};
trait_parent,
clean_impl_generics(cache.parent_stack.last()).as_ref(),
);

cache.search_index.push(index_item);
}
Expand Down
42 changes: 40 additions & 2 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use tracing::{debug, info};
pub(crate) use self::context::*;
pub(crate) use self::span_map::{LinkFromSrc, collect_spans_and_sources};
pub(crate) use self::write_shared::*;
use crate::clean::{self, ItemId, RenderedLink};
use crate::clean::{self, Item, ItemId, RenderedLink};
use crate::display::{Joined as _, MaybeDisplay as _};
use crate::error::Error;
use crate::formats::Impl;
Expand All @@ -79,8 +79,9 @@ use crate::html::format::{
print_impl, print_path, print_type, print_where_clause, visibility_print_with_space,
};
use crate::html::markdown::{
HeadingOffset, IdMap, Markdown, MarkdownItemInfo, MarkdownSummaryLine,
HeadingOffset, IdMap, Markdown, MarkdownItemInfo, MarkdownSummaryLine, short_markdown_summary,
};
use crate::html::render::search_index::get_function_type_for_search;
use crate::html::static_files::SCRAPE_EXAMPLES_HELP_MD;
use crate::html::{highlight, sources};
use crate::scrape_examples::{CallData, CallLocation};
Expand Down Expand Up @@ -144,6 +145,43 @@ pub(crate) struct IndexItem {
pub(crate) deprecation: Option<Deprecation>,
}

impl IndexItem {
pub(crate) fn new(
tcx: TyCtxt<'_>,
cache: &Cache,
item: &Item,
name: Option<Symbol>,
defid: Option<DefId>,
module_path: Vec<Symbol>,
parent_did: Option<DefId>,
impl_id: Option<DefId>,
trait_parent: Option<DefId>,
impl_generics: Option<&(clean::Type, clean::Generics)>,
) -> Self {
let desc = short_markdown_summary(&item.doc_value(), &item.link_names(cache));
let search_type = get_function_type_for_search(item, tcx, impl_generics, parent_did, cache);
let aliases = item.attrs.get_doc_aliases();
let deprecation = item.deprecation(tcx);
Comment on lines +161 to +164
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it makes sense to extract this subset of fields into a separate struct and include is a field on IndexItem?
Then maybe its constructor won't have to handle so many differences in behavior between the two call sites


Self {
ty: item.type_(),
defid: defid.or_else(|| item.item_id.as_def_id()),
name: name.or(item.name).unwrap(),
module_path,
desc,
parent: parent_did,
parent_idx: None,
trait_parent,
trait_parent_idx: None,
exact_module_path: None,
impl_id,
search_type,
aliases,
deprecation,
}
}
}

/// A type used for the search index.
#[derive(Clone, Debug, Eq, PartialEq)]
struct RenderType {
Expand Down
33 changes: 11 additions & 22 deletions src/librustdoc/html/render/search_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1257,29 +1257,18 @@ pub(crate) fn build_index(
&cache.orphan_impl_items
{
if let Some((fqp, _)) = cache.paths.get(&parent) {
let desc = short_markdown_summary(&item.doc_value(), &item.link_names(cache));
search_index.push(IndexItem {
ty: item.type_(),
defid: item.item_id.as_def_id(),
name: item.name.unwrap(),
module_path: fqp[..fqp.len() - 1].to_vec(),
desc,
parent: Some(parent),
parent_idx: None,
trait_parent,
trait_parent_idx: None,
exact_module_path: None,
search_index.push(IndexItem::new(
tcx,
cache,
item,
None,
None,
fqp[..fqp.len() - 1].to_vec(),
None,
impl_id,
search_type: get_function_type_for_search(
item,
tcx,
impl_generics.as_ref(),
Some(parent),
cache,
),
aliases: item.attrs.get_doc_aliases(),
deprecation: item.deprecation(tcx),
});
trait_parent,
impl_generics.as_ref(),
));
}
}

Expand Down
Loading