rustdoc: factor orphan impl items into an actual struct

This commit is contained in:
Michael Howell 2022-05-26 14:01:08 -07:00
parent c516ffa8e5
commit 767719cc30
2 changed files with 20 additions and 12 deletions

View File

@ -107,8 +107,7 @@ pub(crate) struct Cache {
// then the fully qualified name of the structure isn't presented in `paths`
// yet when its implementation methods are being indexed. Caches such methods
// and their parent id here and indexes them at the end of crate parsing.
pub(crate) orphan_impl_items:
Vec<(DefId, clean::Item, Option<(clean::Type, clean::Generics)>, bool)>,
pub(crate) orphan_impl_items: Vec<OrphanImplItem>,
// Similarly to `orphan_impl_items`, sometimes trait impls are picked up
// even though the trait itself is not exported. This can happen if a trait
@ -332,12 +331,12 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
(Some(parent), None) if is_inherent_impl_item => {
// We have a parent, but we don't know where they're
// defined yet. Wait for later to index this item.
self.cache.orphan_impl_items.push((
self.cache.orphan_impl_items.push(OrphanImplItem {
parent,
item.clone(),
self.cache.impl_generics_stack.last().cloned(),
self.cache.parent_is_blanket_or_auto_impl,
));
item: item.clone(),
impl_generics: self.cache.impl_generics_stack.last().cloned(),
parent_is_blanket_or_auto_impl: self.cache.parent_is_blanket_or_auto_impl,
});
}
_ => {}
}
@ -554,3 +553,10 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
ret
}
}
pub(crate) struct OrphanImplItem {
pub(crate) parent: DefId,
pub(crate) item: clean::Item,
pub(crate) impl_generics: Option<(clean::Type, clean::Generics)>,
pub(crate) parent_is_blanket_or_auto_impl: bool,
}

View File

@ -8,7 +8,7 @@
use crate::clean;
use crate::clean::types::{FnRetTy, Function, GenericBound, Generics, Type, WherePredicate};
use crate::formats::cache::Cache;
use crate::formats::cache::{Cache, OrphanImplItem};
use crate::formats::item_type::ItemType;
use crate::html::format::join_with_double_colon;
use crate::html::markdown::short_markdown_summary;
@ -25,8 +25,10 @@ pub(crate) fn build_index<'tcx>(
// Attach all orphan items to the type's definition if the type
// has since been learned.
for &(did, ref item, ref impl_generics, from_blanket_or_auto_impl) in &cache.orphan_impl_items {
if let Some(&(ref fqp, _)) = cache.paths.get(&did) {
for &OrphanImplItem { parent, ref item, ref impl_generics, parent_is_blanket_or_auto_impl } in
&cache.orphan_impl_items
{
if let Some(&(ref fqp, _)) = cache.paths.get(&parent) {
let desc = item
.doc_value()
.map_or_else(String::new, |s| short_markdown_summary(&s, &item.link_names(cache)));
@ -35,13 +37,13 @@ pub(crate) fn build_index<'tcx>(
name: item.name.unwrap().to_string(),
path: join_with_double_colon(&fqp[..fqp.len() - 1]),
desc,
parent: Some(did),
parent: Some(parent),
parent_idx: None,
search_type: get_function_type_for_search(
item,
tcx,
impl_generics.as_ref(),
from_blanket_or_auto_impl,
parent_is_blanket_or_auto_impl,
cache,
),
aliases: item.attrs.get_doc_aliases(),