diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index edf7ddb30dbf9..2f3ab0f47e40d 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -404,6 +404,16 @@ pub(crate) fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span { } impl Item { + /// If `item.name` is `None` and `self` is an `ImportItem`, it'll look for it. + /// + /// It's especially usefully to get the name of `pub use x;` or `pub use x as y;`. + pub(crate) fn full_name(&self) -> Option { + self.name.or_else(|| { + if let ImportItem(ref i) = *self.kind && + let ImportKind::Simple(s) = i.kind { Some(s) } else { None } + }) + } + pub(crate) fn stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option { self.item_id.as_def_id().and_then(|did| tcx.lookup_stability(did)) } diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index f5c0b5e6762bf..332f487c5dd47 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -248,16 +248,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> { } // Index this method for searching later on. - 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 - } - }) { + if let Some(ref s) = item.full_name() && !item.is_stripped() { 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 0de50c60facb3..16bccdb539c54 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2542,16 +2542,7 @@ fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) { let item_sections_in_use: FxHashSet<_> = items .iter() - .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() - }) + .filter(|it| !it.is_stripped() && it.full_name().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)) {