Correctly handle "pub use" reexports
This commit is contained in:
parent
7c0d576c59
commit
31d275e587
6 changed files with 32 additions and 13 deletions
|
@ -514,6 +514,7 @@ fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet<DefId>)
|
|||
},
|
||||
did: None,
|
||||
},
|
||||
false,
|
||||
)),
|
||||
});
|
||||
} else if let Some(i) =
|
||||
|
|
|
@ -2269,12 +2269,12 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
|
|||
visibility: self.vis.clean(cx),
|
||||
stability: None,
|
||||
deprecation: None,
|
||||
inner: ImportItem(Import::Glob(resolve_use_source(cx, path))),
|
||||
inner: ImportItem(Import::Glob(resolve_use_source(cx, path), false)),
|
||||
});
|
||||
return items;
|
||||
}
|
||||
}
|
||||
Import::Glob(resolve_use_source(cx, path))
|
||||
Import::Glob(resolve_use_source(cx, path), true)
|
||||
} else {
|
||||
let name = self.name;
|
||||
if !please_inline {
|
||||
|
@ -2297,6 +2297,9 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
|
|||
Some(self.attrs),
|
||||
&mut visited,
|
||||
) {
|
||||
// In case this is a macro, we don't want to show the reexport, only the macro
|
||||
// itself.
|
||||
let is_macro = matches!(path.res, Res::Def(DefKind::Macro(_), _));
|
||||
items.push(Item {
|
||||
name: None,
|
||||
attrs: self.attrs.clean(cx),
|
||||
|
@ -2308,12 +2311,13 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
|
|||
inner: ImportItem(Import::Simple(
|
||||
self.name.clean(cx),
|
||||
resolve_use_source(cx, path),
|
||||
is_macro,
|
||||
)),
|
||||
});
|
||||
return items;
|
||||
}
|
||||
}
|
||||
Import::Simple(name.clean(cx), resolve_use_source(cx, path))
|
||||
Import::Simple(name.clean(cx), resolve_use_source(cx, path), false)
|
||||
};
|
||||
|
||||
vec![Item {
|
||||
|
|
|
@ -1655,9 +1655,20 @@ pub struct Impl {
|
|||
#[derive(Clone, Debug)]
|
||||
pub enum Import {
|
||||
// use source as str;
|
||||
Simple(String, ImportSource),
|
||||
// The bool indicates wether it imports a macro or not.
|
||||
Simple(String, ImportSource, bool),
|
||||
// use source::*;
|
||||
Glob(ImportSource),
|
||||
// The bool indicates wether this is from an import.
|
||||
Glob(ImportSource, bool),
|
||||
}
|
||||
|
||||
impl Import {
|
||||
pub fn should_be_displayed(&self) -> bool {
|
||||
match *self {
|
||||
Self::Simple(_, _, is_macro) => !is_macro,
|
||||
Self::Glob(_, is_from_import) => is_from_import,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
|
@ -245,6 +245,7 @@ pub struct ExternCrate<'hir> {
|
|||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Import<'hir> {
|
||||
pub name: Symbol,
|
||||
pub id: hir::HirId,
|
||||
|
|
|
@ -1150,14 +1150,14 @@ impl PrintWithSpace for hir::Mutability {
|
|||
impl clean::Import {
|
||||
crate fn print(&self) -> impl fmt::Display + '_ {
|
||||
display_fn(move |f| match *self {
|
||||
clean::Import::Simple(ref name, ref src) => {
|
||||
clean::Import::Simple(ref name, ref src, _) => {
|
||||
if *name == src.path.last_name() {
|
||||
write!(f, "use {};", src.print())
|
||||
} else {
|
||||
write!(f, "use {} as {};", src.print(), *name)
|
||||
}
|
||||
}
|
||||
clean::Import::Glob(ref src) => {
|
||||
clean::Import::Glob(ref src, _) => {
|
||||
if src.path.segments.is_empty() {
|
||||
write!(f, "use *;")
|
||||
} else {
|
||||
|
|
|
@ -2074,12 +2074,14 @@ fn item_module(w: &mut Buffer, cx: &Context, item: &clean::Item, items: &[clean:
|
|||
}
|
||||
|
||||
clean::ImportItem(ref import) => {
|
||||
write!(
|
||||
w,
|
||||
"<tr><td><code>{}{}</code></td></tr>",
|
||||
myitem.visibility.print_with_space(),
|
||||
import.print()
|
||||
);
|
||||
if import.should_be_displayed() {
|
||||
write!(
|
||||
w,
|
||||
"<tr><td><code>{}{}</code></td></tr>",
|
||||
myitem.visibility.print_with_space(),
|
||||
import.print()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_ => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue