1
Fork 0

Restructure a confusing match

This commit is contained in:
Noah Lev 2024-08-02 12:58:59 -07:00
parent 4e2084769b
commit 015aa8d0fb

View file

@ -442,7 +442,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
}
fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::Item, name: Symbol) {
let (parent, is_impl_child) = match *item.kind {
let ((parent_did, parent_path), is_impl_child) = match *item.kind {
clean::StrippedItem(..) => return,
clean::AssocConstItem(..) | clean::AssocTypeItem(..)
if cache.parent_stack.last().is_some_and(|parent| parent.is_trait_impl()) =>
@ -496,8 +496,27 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
_ => ((None, Some(&*cache.stack)), false),
};
match parent {
(parent, Some(path)) if is_impl_child || !cache.stripped_mod => {
if let Some(parent_did) = parent_did
&& parent_path.is_none()
&& is_impl_child
{
// We have a parent, but we don't know where they're
// defined yet. Wait for later to index this item.
let impl_generics = clean_impl_generics(cache.parent_stack.last());
cache.orphan_impl_items.push(OrphanImplItem {
parent: parent_did,
item: item.clone(),
impl_generics,
impl_id: if let Some(ParentStackItem::Impl { item_id, .. }) = cache.parent_stack.last()
{
item_id.as_def_id()
} else {
None
},
});
} else if let Some(path) = parent_path
&& (is_impl_child || !cache.stripped_mod)
{
debug_assert!(!item.is_stripped());
// A crate has a module at its root, containing all items,
@ -527,7 +546,7 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
name,
path: join_with_double_colon(path),
desc,
parent,
parent: parent_did,
parent_idx: None,
exact_path: None,
impl_id: if let Some(ParentStackItem::Impl { item_id, .. }) =
@ -541,7 +560,7 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
&item,
tcx,
clean_impl_generics(cache.parent_stack.last()).as_ref(),
parent,
parent_did,
cache,
),
aliases: item.attrs.get_doc_aliases(),
@ -549,25 +568,6 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
});
}
}
(Some(parent), None) if is_impl_child => {
// We have a parent, but we don't know where they're
// defined yet. Wait for later to index this item.
let impl_generics = clean_impl_generics(cache.parent_stack.last());
cache.orphan_impl_items.push(OrphanImplItem {
parent,
item: item.clone(),
impl_generics,
impl_id: if let Some(ParentStackItem::Impl { item_id, .. }) =
cache.parent_stack.last()
{
item_id.as_def_id()
} else {
None
},
});
}
_ => {}
}
}
pub(crate) struct OrphanImplItem {