Restructure a confusing match
This commit is contained in:
parent
4e2084769b
commit
015aa8d0fb
@ -442,7 +442,7 @@ fn is_from_private_dep(tcx: TyCtxt<'_>, cache: &Cache, def_id: DefId) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::Item, name: Symbol) {
|
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::StrippedItem(..) => return,
|
||||||
clean::AssocConstItem(..) | clean::AssocTypeItem(..)
|
clean::AssocConstItem(..) | clean::AssocTypeItem(..)
|
||||||
if cache.parent_stack.last().is_some_and(|parent| parent.is_trait_impl()) =>
|
if cache.parent_stack.last().is_some_and(|parent| parent.is_trait_impl()) =>
|
||||||
@ -496,67 +496,59 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
|
|||||||
_ => ((None, Some(&*cache.stack)), false),
|
_ => ((None, Some(&*cache.stack)), false),
|
||||||
};
|
};
|
||||||
|
|
||||||
match parent {
|
if let Some(parent_did) = parent_did
|
||||||
(parent, Some(path)) if is_impl_child || !cache.stripped_mod => {
|
&& parent_path.is_none()
|
||||||
debug_assert!(!item.is_stripped());
|
&& is_impl_child
|
||||||
|
{
|
||||||
// A crate has a module at its root, containing all items,
|
// We have a parent, but we don't know where they're
|
||||||
// which should not be indexed. The crate-item itself is
|
// defined yet. Wait for later to index this item.
|
||||||
// inserted later on when serializing the search-index.
|
let impl_generics = clean_impl_generics(cache.parent_stack.last());
|
||||||
if item.item_id.as_def_id().is_some_and(|idx| !idx.is_crate_root())
|
cache.orphan_impl_items.push(OrphanImplItem {
|
||||||
&& let ty = item.type_()
|
parent: parent_did,
|
||||||
&& (ty != ItemType::StructField || u16::from_str_radix(name.as_str(), 10).is_err())
|
item: item.clone(),
|
||||||
|
impl_generics,
|
||||||
|
impl_id: if let Some(ParentStackItem::Impl { item_id, .. }) = cache.parent_stack.last()
|
||||||
{
|
{
|
||||||
let desc = short_markdown_summary(&item.doc_value(), &item.link_names(cache));
|
item_id.as_def_id()
|
||||||
// For searching purposes, a re-export is a duplicate if:
|
} else {
|
||||||
//
|
None
|
||||||
// - It's either an inline, or a true re-export
|
},
|
||||||
// - It's got the same name
|
});
|
||||||
// - Both of them have the same exact path
|
} else if let Some(path) = parent_path
|
||||||
let defid = (match &*item.kind {
|
&& (is_impl_child || !cache.stripped_mod)
|
||||||
&clean::ItemKind::ImportItem(ref import) => import.source.did,
|
{
|
||||||
_ => None,
|
debug_assert!(!item.is_stripped());
|
||||||
})
|
|
||||||
.or_else(|| item.item_id.as_def_id());
|
// A crate has a module at its root, containing all items,
|
||||||
// In case this is a field from a tuple struct, we don't add it into
|
// which should not be indexed. The crate-item itself is
|
||||||
// the search index because its name is something like "0", which is
|
// inserted later on when serializing the search-index.
|
||||||
// not useful for rustdoc search.
|
if item.item_id.as_def_id().is_some_and(|idx| !idx.is_crate_root())
|
||||||
cache.search_index.push(IndexItem {
|
&& let ty = item.type_()
|
||||||
ty,
|
&& (ty != ItemType::StructField || u16::from_str_radix(name.as_str(), 10).is_err())
|
||||||
defid,
|
{
|
||||||
name,
|
let desc = short_markdown_summary(&item.doc_value(), &item.link_names(cache));
|
||||||
path: join_with_double_colon(path),
|
// For searching purposes, a re-export is a duplicate if:
|
||||||
desc,
|
//
|
||||||
parent,
|
// - It's either an inline, or a true re-export
|
||||||
parent_idx: None,
|
// - It's got the same name
|
||||||
exact_path: None,
|
// - Both of them have the same exact path
|
||||||
impl_id: if let Some(ParentStackItem::Impl { item_id, .. }) =
|
let defid = (match &*item.kind {
|
||||||
cache.parent_stack.last()
|
&clean::ItemKind::ImportItem(ref import) => import.source.did,
|
||||||
{
|
_ => None,
|
||||||
item_id.as_def_id()
|
})
|
||||||
} else {
|
.or_else(|| item.item_id.as_def_id());
|
||||||
None
|
// In case this is a field from a tuple struct, we don't add it into
|
||||||
},
|
// the search index because its name is something like "0", which is
|
||||||
search_type: get_function_type_for_search(
|
// not useful for rustdoc search.
|
||||||
&item,
|
cache.search_index.push(IndexItem {
|
||||||
tcx,
|
ty,
|
||||||
clean_impl_generics(cache.parent_stack.last()).as_ref(),
|
defid,
|
||||||
parent,
|
name,
|
||||||
cache,
|
path: join_with_double_colon(path),
|
||||||
),
|
desc,
|
||||||
aliases: item.attrs.get_doc_aliases(),
|
parent: parent_did,
|
||||||
deprecation: item.deprecation(tcx),
|
parent_idx: None,
|
||||||
});
|
exact_path: None,
|
||||||
}
|
|
||||||
}
|
|
||||||
(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, .. }) =
|
impl_id: if let Some(ParentStackItem::Impl { item_id, .. }) =
|
||||||
cache.parent_stack.last()
|
cache.parent_stack.last()
|
||||||
{
|
{
|
||||||
@ -564,9 +556,17 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
|
search_type: get_function_type_for_search(
|
||||||
|
&item,
|
||||||
|
tcx,
|
||||||
|
clean_impl_generics(cache.parent_stack.last()).as_ref(),
|
||||||
|
parent_did,
|
||||||
|
cache,
|
||||||
|
),
|
||||||
|
aliases: item.attrs.get_doc_aliases(),
|
||||||
|
deprecation: item.deprecation(tcx),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user