diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2020-09-28 00:18:09 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2020-10-09 20:25:44 +0200 |
| commit | 31d275e5877d983fecb39bbaad837f6b7cf120d3 (patch) | |
| tree | 88b79ccd983dcdb7ca4a2a3c555f77af921d2e19 /src | |
| parent | 7c0d576c59e9429157449e617ec5607373afc642 (diff) | |
| download | rust-31d275e5877d983fecb39bbaad837f6b7cf120d3.tar.gz rust-31d275e5877d983fecb39bbaad837f6b7cf120d3.zip | |
Correctly handle "pub use" reexports
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/clean/inline.rs | 1 | ||||
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 10 | ||||
| -rw-r--r-- | src/librustdoc/clean/types.rs | 15 | ||||
| -rw-r--r-- | src/librustdoc/doctree.rs | 1 | ||||
| -rw-r--r-- | src/librustdoc/html/format.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 14 |
6 files changed, 32 insertions, 13 deletions
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index a6c754ab67f..17f9411fca8 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -514,6 +514,7 @@ fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet<DefId>) }, did: None, }, + false, )), }); } else if let Some(i) = diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index ca9d76f4cf4..daa9f1df649 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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 { diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 179cf248846..8b14b3e5de2 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -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)] diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 6bb9b58bead..ee217d99d2c 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -245,6 +245,7 @@ pub struct ExternCrate<'hir> { pub span: Span, } +#[derive(Debug)] pub struct Import<'hir> { pub name: Symbol, pub id: hir::HirId, diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 2da9c68b196..ece0c247fb5 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -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 { diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index afd1dc59642..a74e768f980 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -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() + ); + } } _ => { |
