Skip to content

Commit 767719c

Browse files
committed
rustdoc: factor orphan impl items into an actual struct
1 parent c516ffa commit 767719c

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/librustdoc/formats/cache.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ pub(crate) struct Cache {
107107
// then the fully qualified name of the structure isn't presented in `paths`
108108
// yet when its implementation methods are being indexed. Caches such methods
109109
// and their parent id here and indexes them at the end of crate parsing.
110-
pub(crate) orphan_impl_items:
111-
Vec<(DefId, clean::Item, Option<(clean::Type, clean::Generics)>, bool)>,
110+
pub(crate) orphan_impl_items: Vec<OrphanImplItem>,
112111

113112
// Similarly to `orphan_impl_items`, sometimes trait impls are picked up
114113
// even though the trait itself is not exported. This can happen if a trait
@@ -332,12 +331,12 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
332331
(Some(parent), None) if is_inherent_impl_item => {
333332
// We have a parent, but we don't know where they're
334333
// defined yet. Wait for later to index this item.
335-
self.cache.orphan_impl_items.push((
334+
self.cache.orphan_impl_items.push(OrphanImplItem {
336335
parent,
337-
item.clone(),
338-
self.cache.impl_generics_stack.last().cloned(),
339-
self.cache.parent_is_blanket_or_auto_impl,
340-
));
336+
item: item.clone(),
337+
impl_generics: self.cache.impl_generics_stack.last().cloned(),
338+
parent_is_blanket_or_auto_impl: self.cache.parent_is_blanket_or_auto_impl,
339+
});
341340
}
342341
_ => {}
343342
}
@@ -554,3 +553,10 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
554553
ret
555554
}
556555
}
556+
557+
pub(crate) struct OrphanImplItem {
558+
pub(crate) parent: DefId,
559+
pub(crate) item: clean::Item,
560+
pub(crate) impl_generics: Option<(clean::Type, clean::Generics)>,
561+
pub(crate) parent_is_blanket_or_auto_impl: bool,
562+
}

src/librustdoc/html/render/search_index.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serde::ser::{Serialize, SerializeStruct, Serializer};
88

99
use crate::clean;
1010
use crate::clean::types::{FnRetTy, Function, GenericBound, Generics, Type, WherePredicate};
11-
use crate::formats::cache::Cache;
11+
use crate::formats::cache::{Cache, OrphanImplItem};
1212
use crate::formats::item_type::ItemType;
1313
use crate::html::format::join_with_double_colon;
1414
use crate::html::markdown::short_markdown_summary;
@@ -25,8 +25,10 @@ pub(crate) fn build_index<'tcx>(
2525

2626
// Attach all orphan items to the type's definition if the type
2727
// has since been learned.
28-
for &(did, ref item, ref impl_generics, from_blanket_or_auto_impl) in &cache.orphan_impl_items {
29-
if let Some(&(ref fqp, _)) = cache.paths.get(&did) {
28+
for &OrphanImplItem { parent, ref item, ref impl_generics, parent_is_blanket_or_auto_impl } in
29+
&cache.orphan_impl_items
30+
{
31+
if let Some(&(ref fqp, _)) = cache.paths.get(&parent) {
3032
let desc = item
3133
.doc_value()
3234
.map_or_else(String::new, |s| short_markdown_summary(&s, &item.link_names(cache)));
@@ -35,13 +37,13 @@ pub(crate) fn build_index<'tcx>(
3537
name: item.name.unwrap().to_string(),
3638
path: join_with_double_colon(&fqp[..fqp.len() - 1]),
3739
desc,
38-
parent: Some(did),
40+
parent: Some(parent),
3941
parent_idx: None,
4042
search_type: get_function_type_for_search(
4143
item,
4244
tcx,
4345
impl_generics.as_ref(),
44-
from_blanket_or_auto_impl,
46+
parent_is_blanket_or_auto_impl,
4547
cache,
4648
),
4749
aliases: item.attrs.get_doc_aliases(),

0 commit comments

Comments
 (0)