rustdoc: factor orphan impl items into an actual struct
This commit is contained in:
parent
c516ffa8e5
commit
767719cc30
@ -107,8 +107,7 @@ pub(crate) struct Cache {
|
|||||||
// then the fully qualified name of the structure isn't presented in `paths`
|
// then the fully qualified name of the structure isn't presented in `paths`
|
||||||
// yet when its implementation methods are being indexed. Caches such methods
|
// 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.
|
// and their parent id here and indexes them at the end of crate parsing.
|
||||||
pub(crate) orphan_impl_items:
|
pub(crate) orphan_impl_items: Vec<OrphanImplItem>,
|
||||||
Vec<(DefId, clean::Item, Option<(clean::Type, clean::Generics)>, bool)>,
|
|
||||||
|
|
||||||
// Similarly to `orphan_impl_items`, sometimes trait impls are picked up
|
// 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
|
// 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 => {
|
(Some(parent), None) if is_inherent_impl_item => {
|
||||||
// We have a parent, but we don't know where they're
|
// We have a parent, but we don't know where they're
|
||||||
// defined yet. Wait for later to index this item.
|
// defined yet. Wait for later to index this item.
|
||||||
self.cache.orphan_impl_items.push((
|
self.cache.orphan_impl_items.push(OrphanImplItem {
|
||||||
parent,
|
parent,
|
||||||
item.clone(),
|
item: item.clone(),
|
||||||
self.cache.impl_generics_stack.last().cloned(),
|
impl_generics: self.cache.impl_generics_stack.last().cloned(),
|
||||||
self.cache.parent_is_blanket_or_auto_impl,
|
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
|
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,
|
||||||
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
use crate::clean;
|
use crate::clean;
|
||||||
use crate::clean::types::{FnRetTy, Function, GenericBound, Generics, Type, WherePredicate};
|
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::formats::item_type::ItemType;
|
||||||
use crate::html::format::join_with_double_colon;
|
use crate::html::format::join_with_double_colon;
|
||||||
use crate::html::markdown::short_markdown_summary;
|
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
|
// Attach all orphan items to the type's definition if the type
|
||||||
// has since been learned.
|
// has since been learned.
|
||||||
for &(did, ref item, ref impl_generics, from_blanket_or_auto_impl) in &cache.orphan_impl_items {
|
for &OrphanImplItem { parent, ref item, ref impl_generics, parent_is_blanket_or_auto_impl } in
|
||||||
if let Some(&(ref fqp, _)) = cache.paths.get(&did) {
|
&cache.orphan_impl_items
|
||||||
|
{
|
||||||
|
if let Some(&(ref fqp, _)) = cache.paths.get(&parent) {
|
||||||
let desc = item
|
let desc = item
|
||||||
.doc_value()
|
.doc_value()
|
||||||
.map_or_else(String::new, |s| short_markdown_summary(&s, &item.link_names(cache)));
|
.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(),
|
name: item.name.unwrap().to_string(),
|
||||||
path: join_with_double_colon(&fqp[..fqp.len() - 1]),
|
path: join_with_double_colon(&fqp[..fqp.len() - 1]),
|
||||||
desc,
|
desc,
|
||||||
parent: Some(did),
|
parent: Some(parent),
|
||||||
parent_idx: None,
|
parent_idx: None,
|
||||||
search_type: get_function_type_for_search(
|
search_type: get_function_type_for_search(
|
||||||
item,
|
item,
|
||||||
tcx,
|
tcx,
|
||||||
impl_generics.as_ref(),
|
impl_generics.as_ref(),
|
||||||
from_blanket_or_auto_impl,
|
parent_is_blanket_or_auto_impl,
|
||||||
cache,
|
cache,
|
||||||
),
|
),
|
||||||
aliases: item.attrs.get_doc_aliases(),
|
aliases: item.attrs.get_doc_aliases(),
|
||||||
|
Loading…
Reference in New Issue
Block a user