Skip to content

Commit

Permalink
Create Item::full_name method to include name of reexports
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed May 21, 2022
1 parent 4f372b1 commit 41db4ec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
10 changes: 10 additions & 0 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Symbol> {
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<Stability> {
self.item_id.as_def_id().and_then(|did| tcx.lookup_stability(did))
}
Expand Down
11 changes: 1 addition & 10 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..)
Expand Down
11 changes: 1 addition & 10 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 41db4ec

Please sign in to comment.