Skip to content

Commit 883c177

Browse files
Move doc alias discovery into the Attributes struct and some code improvements
1 parent f581cf7 commit 883c177

File tree

4 files changed

+15
-39
lines changed

4 files changed

+15
-39
lines changed

src/librustdoc/clean/types.rs

+9
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,15 @@ impl Attributes {
643643
})
644644
.collect()
645645
}
646+
647+
pub fn get_doc_aliases(&self) -> FxHashSet<String> {
648+
self.other_attrs
649+
.lists(sym::doc)
650+
.filter(|a| a.check_name(sym::alias))
651+
.filter_map(|a| a.value_str().map(|s| s.to_string().replace("\"", "")))
652+
.filter(|v| !v.is_empty())
653+
.collect::<FxHashSet<_>>()
654+
}
646655
}
647656

648657
impl PartialEq for Attributes {

src/librustdoc/html/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ pub struct RenderInfo {
278278
/// Struct representing one entry in the JS search index. These are all emitted
279279
/// by hand to a large JS file at the end of cache-creation.
280280
#[derive(Debug)]
281-
pub struct IndexItem {
281+
struct IndexItem {
282282
ty: ItemType,
283283
name: String,
284284
path: String,

src/librustdoc/html/render/cache.rs

+4-37
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,7 @@ impl DocFolder for Cache {
328328
search_type: get_index_search_type(&item),
329329
});
330330

331-
for alias in item
332-
.attrs
333-
.lists(sym::doc)
334-
.filter(|a| a.check_name(sym::alias))
335-
.filter_map(|a| a.value_str().map(|s| s.to_string().replace("\"", "")))
336-
.filter(|v| !v.is_empty())
337-
.collect::<FxHashSet<_>>()
338-
.into_iter()
339-
{
331+
for alias in item.attrs.get_doc_aliases() {
340332
self.aliases
341333
.entry(alias.to_lowercase())
342334
.or_insert(Vec::with_capacity(1))
@@ -378,9 +370,6 @@ impl DocFolder for Cache {
378370
| clean::MacroItem(..)
379371
| clean::ProcMacroItem(..)
380372
| clean::VariantItem(..)
381-
| clean::StructFieldItem(..)
382-
| clean::TyMethodItem(..)
383-
| clean::MethodItem(..)
384373
if !self.stripped_mod =>
385374
{
386375
// Re-exported items mean that the same id can show up twice
@@ -564,15 +553,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
564553
parent_idx: None,
565554
search_type: get_index_search_type(&item),
566555
});
567-
for alias in item
568-
.attrs
569-
.lists(sym::doc)
570-
.filter(|a| a.check_name(sym::alias))
571-
.filter_map(|a| a.value_str().map(|s| s.to_string().replace("\"", "")))
572-
.filter(|v| !v.is_empty())
573-
.collect::<FxHashSet<_>>()
574-
.into_iter()
575-
{
556+
for alias in item.attrs.get_doc_aliases().into_iter() {
576557
aliases
577558
.entry(alias.to_lowercase())
578559
.or_insert(Vec::with_capacity(1))
@@ -619,22 +600,8 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
619600
.map(|module| shorten(plain_summary_line(module.doc_value())))
620601
.unwrap_or(String::new());
621602

622-
let crate_aliases = aliases
623-
.iter()
624-
.map(|(k, values)| {
625-
(
626-
k.clone(),
627-
values
628-
.iter()
629-
.filter_map(|v| {
630-
let x = &crate_items[*v];
631-
if x.parent_idx.is_some() == x.parent.is_some() { Some(*v) } else { None }
632-
})
633-
.collect::<Vec<_>>(),
634-
)
635-
})
636-
.filter(|(_, values)| !values.is_empty())
637-
.collect::<Vec<_>>();
603+
let crate_aliases =
604+
aliases.iter().map(|(k, values)| (k.clone(), values.clone())).collect::<Vec<_>>();
638605

639606
#[derive(Serialize)]
640607
struct CrateData<'a> {

src/librustdoc/html/static/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ function getSearchElement() {
972972
desc: item.desc,
973973
ty: item.ty,
974974
parent: item.parent,
975-
type: item.parent,
975+
type: item.type,
976976
is_alias: true,
977977
};
978978
}

0 commit comments

Comments
 (0)