about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2022-05-26 14:01:08 -0700
committerMichael Howell <michael@notriddle.com>2022-05-26 14:40:48 -0700
commit767719cc304e9b025875aea073f66ce248ae2616 (patch)
tree1f679394195a5ac22136b3ed077626cff74b8bd0
parentc516ffa8e531290687b60bb8023fbccd3abe43ad (diff)
downloadrust-767719cc304e9b025875aea073f66ce248ae2616.tar.gz
rust-767719cc304e9b025875aea073f66ce248ae2616.zip
rustdoc: factor orphan impl items into an actual struct
-rw-r--r--src/librustdoc/formats/cache.rs20
-rw-r--r--src/librustdoc/html/render/search_index.rs12
2 files changed, 20 insertions, 12 deletions
diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs
index 813e6fa24ec..9b2756b1d5c 100644
--- a/src/librustdoc/formats/cache.rs
+++ b/src/librustdoc/formats/cache.rs
@@ -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 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
                 (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 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
         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,
+}
diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs
index 323c0e89f29..dcdf18978e3 100644
--- a/src/librustdoc/html/render/search_index.rs
+++ b/src/librustdoc/html/render/search_index.rs
@@ -8,7 +8,7 @@ use serde::ser::{Serialize, SerializeStruct, Serializer};
 
 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(),