Skip to content

Commit a39f59d

Browse files
committed
Separate out some fields into "sub-struct" (name pending bikeshed)
1 parent acd4d7e commit a39f59d

File tree

3 files changed

+58
-61
lines changed

3 files changed

+58
-61
lines changed

src/librustdoc/formats/cache.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::core::DocContext;
1515
use crate::fold::DocFolder;
1616
use crate::formats::Impl;
1717
use crate::formats::item_type::ItemType;
18-
use crate::html::render::IndexItem;
18+
use crate::html::render::{IndexItem, IndexItemSubStruct};
1919
use crate::visit_lib::RustdocEffectiveVisibilities;
2020

2121
/// This cache is used to store information about the [`clean::Crate`] being
@@ -582,18 +582,26 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
582582
_ => item_def_id,
583583
};
584584
let (impl_id, trait_parent) = cache.parent_stack_last_impl_and_trait_id();
585-
let index_item = IndexItem::new(
585+
let sub_struct = IndexItemSubStruct::new(
586586
tcx,
587587
cache,
588588
item,
589-
Some(name),
590-
Some(defid),
591-
parent_path.to_vec(),
592589
parent_did,
593-
impl_id,
594-
trait_parent,
595590
clean_impl_generics(cache.parent_stack.last()).as_ref(),
596591
);
592+
let index_item = IndexItem {
593+
ty: item.type_(),
594+
defid: Some(defid),
595+
name,
596+
module_path: parent_path.to_vec(),
597+
parent: parent_did,
598+
parent_idx: None,
599+
trait_parent,
600+
trait_parent_idx: None,
601+
exact_module_path: None,
602+
impl_id,
603+
sub_struct,
604+
};
597605

598606
cache.search_index.push(index_item);
599607
}

src/librustdoc/html/render/mod.rs

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ use crate::html::format::{
8181
use crate::html::markdown::{
8282
HeadingOffset, IdMap, Markdown, MarkdownItemInfo, MarkdownSummaryLine, short_markdown_summary,
8383
};
84-
use crate::html::render::search_index::get_function_type_for_search;
8584
use crate::html::static_files::SCRAPE_EXAMPLES_HELP_MD;
8685
use crate::html::{highlight, sources};
8786
use crate::scrape_examples::{CallData, CallLocation};
@@ -125,63 +124,48 @@ enum RenderMode {
125124
// Helper structs for rendering items/sidebars and carrying along contextual
126125
// information
127126

128-
/// Struct representing one entry in the JS search index. These are all emitted
129-
/// by hand to a large JS file at the end of cache-creation.
130127
#[derive(Debug)]
131-
pub(crate) struct IndexItem {
132-
pub(crate) ty: ItemType,
133-
pub(crate) defid: Option<DefId>,
134-
pub(crate) name: Symbol,
135-
pub(crate) module_path: Vec<Symbol>,
128+
pub(crate) struct IndexItemSubStruct {
136129
pub(crate) desc: String,
137-
pub(crate) parent: Option<DefId>,
138-
pub(crate) parent_idx: Option<usize>,
139-
pub(crate) trait_parent: Option<DefId>,
140-
pub(crate) trait_parent_idx: Option<usize>,
141-
pub(crate) exact_module_path: Option<Vec<Symbol>>,
142-
pub(crate) impl_id: Option<DefId>,
143130
pub(crate) search_type: Option<IndexItemFunctionType>,
144131
pub(crate) aliases: Box<[Symbol]>,
145132
pub(crate) deprecation: Option<Deprecation>,
146133
}
147134

148-
impl IndexItem {
135+
impl IndexItemSubStruct {
149136
pub(crate) fn new(
150137
tcx: TyCtxt<'_>,
151138
cache: &Cache,
152139
item: &Item,
153-
name: Option<Symbol>,
154-
defid: Option<DefId>,
155-
module_path: Vec<Symbol>,
156140
parent_did: Option<DefId>,
157-
impl_id: Option<DefId>,
158-
trait_parent: Option<DefId>,
159141
impl_generics: Option<&(clean::Type, clean::Generics)>,
160142
) -> Self {
161143
let desc = short_markdown_summary(&item.doc_value(), &item.link_names(cache));
162-
let search_type = get_function_type_for_search(item, tcx, impl_generics, parent_did, cache);
144+
let search_type =
145+
search_index::get_function_type_for_search(item, tcx, impl_generics, parent_did, cache);
163146
let aliases = item.attrs.get_doc_aliases();
164147
let deprecation = item.deprecation(tcx);
165-
166-
Self {
167-
ty: item.type_(),
168-
defid: defid.or_else(|| item.item_id.as_def_id()),
169-
name: name.or(item.name).unwrap(),
170-
module_path,
171-
desc,
172-
parent: parent_did,
173-
parent_idx: None,
174-
trait_parent,
175-
trait_parent_idx: None,
176-
exact_module_path: None,
177-
impl_id,
178-
search_type,
179-
aliases,
180-
deprecation,
181-
}
148+
Self { desc, search_type, aliases, deprecation }
182149
}
183150
}
184151

152+
/// Struct representing one entry in the JS search index. These are all emitted
153+
/// by hand to a large JS file at the end of cache-creation.
154+
#[derive(Debug)]
155+
pub(crate) struct IndexItem {
156+
pub(crate) ty: ItemType,
157+
pub(crate) defid: Option<DefId>,
158+
pub(crate) name: Symbol,
159+
pub(crate) module_path: Vec<Symbol>,
160+
pub(crate) parent: Option<DefId>,
161+
pub(crate) parent_idx: Option<usize>,
162+
pub(crate) trait_parent: Option<DefId>,
163+
pub(crate) trait_parent_idx: Option<usize>,
164+
pub(crate) exact_module_path: Option<Vec<Symbol>>,
165+
pub(crate) impl_id: Option<DefId>,
166+
pub(crate) sub_struct: IndexItemSubStruct,
167+
}
168+
185169
/// A type used for the search index.
186170
#[derive(Clone, Debug, Eq, PartialEq)]
187171
struct RenderType {

src/librustdoc/html/render/search_index.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ use crate::error::Error;
2929
use crate::formats::cache::{Cache, OrphanImplItem};
3030
use crate::formats::item_type::ItemType;
3131
use crate::html::markdown::short_markdown_summary;
32-
use crate::html::render::{self, IndexItem, IndexItemFunctionType, RenderType, RenderTypeId};
32+
use crate::html::render::{
33+
self, IndexItem, IndexItemFunctionType, IndexItemSubStruct, RenderType, RenderTypeId,
34+
};
3335

3436
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
3537
pub(crate) struct SerializedSearchIndex {
@@ -1261,18 +1263,21 @@ pub(crate) fn build_index(
12611263
&cache.orphan_impl_items
12621264
{
12631265
if let Some((fqp, _)) = cache.paths.get(&parent) {
1264-
search_index.push(IndexItem::new(
1265-
tcx,
1266-
cache,
1267-
item,
1268-
None,
1269-
None,
1270-
fqp[..fqp.len() - 1].to_vec(),
1271-
Some(parent),
1272-
impl_id,
1266+
let sub_struct =
1267+
IndexItemSubStruct::new(tcx, cache, item, Some(parent), impl_generics.as_ref());
1268+
search_index.push(IndexItem {
1269+
ty: item.type_(),
1270+
defid: item.item_id.as_def_id(),
1271+
name: item.name.unwrap(),
1272+
module_path: fqp[..fqp.len() - 1].to_vec(),
1273+
parent: Some(parent),
1274+
parent_idx: None,
12731275
trait_parent,
1274-
impl_generics.as_ref(),
1275-
));
1276+
trait_parent_idx: None,
1277+
exact_module_path: None,
1278+
impl_id,
1279+
sub_struct,
1280+
});
12761281
}
12771282
}
12781283

@@ -1508,7 +1513,7 @@ pub(crate) fn build_index(
15081513
trait_parent: item.trait_parent_idx,
15091514
module_path,
15101515
exact_module_path,
1511-
deprecated: item.deprecation.is_some(),
1516+
deprecated: item.sub_struct.deprecation.is_some(),
15121517
associated_item_disambiguator: if let Some(impl_id) = item.impl_id
15131518
&& let Some(parent_idx) = item.parent_idx
15141519
&& associated_item_duplicates
@@ -1523,12 +1528,12 @@ pub(crate) fn build_index(
15231528
},
15241529
krate: crate_idx,
15251530
},
1526-
item.desc.to_string(),
1531+
item.sub_struct.desc.to_string(),
15271532
);
15281533

15291534
// Aliases
15301535
// -------
1531-
for alias in &item.aliases[..] {
1536+
for alias in &item.sub_struct.aliases {
15321537
serialized_index.push_alias(alias.as_str().to_string(), new_entry_id);
15331538
}
15341539

@@ -1801,7 +1806,7 @@ pub(crate) fn build_index(
18011806
_ => {}
18021807
}
18031808
}
1804-
if let Some(search_type) = &mut item.search_type {
1809+
if let Some(search_type) = &mut item.sub_struct.search_type {
18051810
let mut used_in_function_inputs = BTreeSet::new();
18061811
let mut used_in_function_output = BTreeSet::new();
18071812
for item in &mut search_type.inputs {

0 commit comments

Comments
 (0)