From 279dee5374dbaaf7c33ddb584bf29061a4971e05 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 5 May 2022 21:56:03 +0200 Subject: [PATCH] Fix reexports missing from the search index --- src/librustdoc/formats/cache.rs | 11 ++++++++++- src/librustdoc/html/render/mod.rs | 11 ++++++++++- src/librustdoc/html/render/print_item.rs | 7 ++++++- src/librustdoc/html/static/js/search.js | 3 +++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index b4d2772b31d..30190138750 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -248,7 +248,16 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> { } // Index this method for searching later on. - if let Some(ref s) = item.name { + if let Some(ref s) = item.name.or_else(|| { + if item.is_stripped() { + None + } else if let clean::ImportItem(ref i) = *item.kind && + let clean::ImportKind::Simple(s) = i.kind { + Some(s) + } else { + None + } + }) { let (parent, is_inherent_impl_item) = match *item.kind { clean::StrippedItem(..) => ((None, None), false), clean::AssocConstItem(..) | clean::AssocTypeItem(..) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index fedeb449b2e..19582481910 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2542,7 +2542,16 @@ fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) { let item_sections_in_use: FxHashSet<_> = items .iter() - .filter(|it| !it.is_stripped() && it.name.is_some()) + .filter(|it| { + !it.is_stripped() + && it + .name + .or_else(|| { + if let clean::ImportItem(ref i) = *it.kind && + let clean::ImportKind::Simple(s) = i.kind { Some(s) } else { None } + }) + .is_some() + }) .map(|it| item_ty_to_section(it.type_())) .collect(); for &sec in ItemSection::ALL.iter().filter(|sec| item_sections_in_use.contains(sec)) { diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index f1915920b6d..0ad54abf807 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -346,7 +346,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl w.write_str(ITEM_TABLE_ROW_OPEN); write!( w, - "
\ + "
\ {vis}{imp}\
\
{stab_tags}
", @@ -355,6 +355,11 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl vis = myitem.visibility.print_with_space(myitem.item_id, cx), imp = import.print(cx), stab_tags = stab_tags.unwrap_or_default(), + id = match import.kind { + clean::ImportKind::Simple(s) => + format!(" id=\"{}\"", cx.derive_id(format!("reexport.{}", s))), + clean::ImportKind::Glob => String::new(), + }, ); w.write_str(ITEM_TABLE_ROW_CLOSE); } diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 60ad431ba7a..ba4e3f82565 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -1507,6 +1507,9 @@ window.initSearch = rawSearchIndex => { displayPath = path + "::"; href = window.rootPath + path.replace(/::/g, "/") + "/" + name + "/index.html"; + } else if (type === "import") { + displayPath = item.path + "::"; + href = window.rootPath + item.path.replace(/::/g, "/") + "/index.html#reexport." + name; } else if (type === "primitive" || type === "keyword") { displayPath = ""; href = window.rootPath + path.replace(/::/g, "/") +