Skip to content

Commit 31d275e

Browse files
Correctly handle "pub use" reexports
1 parent 7c0d576 commit 31d275e

File tree

6 files changed

+32
-13
lines changed

6 files changed

+32
-13
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet<DefId>)
514514
},
515515
did: None,
516516
},
517+
false,
517518
)),
518519
});
519520
} else if let Some(i) =

src/librustdoc/clean/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,12 +2269,12 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
22692269
visibility: self.vis.clean(cx),
22702270
stability: None,
22712271
deprecation: None,
2272-
inner: ImportItem(Import::Glob(resolve_use_source(cx, path))),
2272+
inner: ImportItem(Import::Glob(resolve_use_source(cx, path), false)),
22732273
});
22742274
return items;
22752275
}
22762276
}
2277-
Import::Glob(resolve_use_source(cx, path))
2277+
Import::Glob(resolve_use_source(cx, path), true)
22782278
} else {
22792279
let name = self.name;
22802280
if !please_inline {
@@ -2297,6 +2297,9 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
22972297
Some(self.attrs),
22982298
&mut visited,
22992299
) {
2300+
// In case this is a macro, we don't want to show the reexport, only the macro
2301+
// itself.
2302+
let is_macro = matches!(path.res, Res::Def(DefKind::Macro(_), _));
23002303
items.push(Item {
23012304
name: None,
23022305
attrs: self.attrs.clean(cx),
@@ -2308,12 +2311,13 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
23082311
inner: ImportItem(Import::Simple(
23092312
self.name.clean(cx),
23102313
resolve_use_source(cx, path),
2314+
is_macro,
23112315
)),
23122316
});
23132317
return items;
23142318
}
23152319
}
2316-
Import::Simple(name.clean(cx), resolve_use_source(cx, path))
2320+
Import::Simple(name.clean(cx), resolve_use_source(cx, path), false)
23172321
};
23182322

23192323
vec![Item {

src/librustdoc/clean/types.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,9 +1655,20 @@ pub struct Impl {
16551655
#[derive(Clone, Debug)]
16561656
pub enum Import {
16571657
// use source as str;
1658-
Simple(String, ImportSource),
1658+
// The bool indicates wether it imports a macro or not.
1659+
Simple(String, ImportSource, bool),
16591660
// use source::*;
1660-
Glob(ImportSource),
1661+
// The bool indicates wether this is from an import.
1662+
Glob(ImportSource, bool),
1663+
}
1664+
1665+
impl Import {
1666+
pub fn should_be_displayed(&self) -> bool {
1667+
match *self {
1668+
Self::Simple(_, _, is_macro) => !is_macro,
1669+
Self::Glob(_, is_from_import) => is_from_import,
1670+
}
1671+
}
16611672
}
16621673

16631674
#[derive(Clone, Debug)]

src/librustdoc/doctree.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ pub struct ExternCrate<'hir> {
245245
pub span: Span,
246246
}
247247

248+
#[derive(Debug)]
248249
pub struct Import<'hir> {
249250
pub name: Symbol,
250251
pub id: hir::HirId,

src/librustdoc/html/format.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,14 +1150,14 @@ impl PrintWithSpace for hir::Mutability {
11501150
impl clean::Import {
11511151
crate fn print(&self) -> impl fmt::Display + '_ {
11521152
display_fn(move |f| match *self {
1153-
clean::Import::Simple(ref name, ref src) => {
1153+
clean::Import::Simple(ref name, ref src, _) => {
11541154
if *name == src.path.last_name() {
11551155
write!(f, "use {};", src.print())
11561156
} else {
11571157
write!(f, "use {} as {};", src.print(), *name)
11581158
}
11591159
}
1160-
clean::Import::Glob(ref src) => {
1160+
clean::Import::Glob(ref src, _) => {
11611161
if src.path.segments.is_empty() {
11621162
write!(f, "use *;")
11631163
} else {

src/librustdoc/html/render/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,12 +2074,14 @@ fn item_module(w: &mut Buffer, cx: &Context, item: &clean::Item, items: &[clean:
20742074
}
20752075

20762076
clean::ImportItem(ref import) => {
2077-
write!(
2078-
w,
2079-
"<tr><td><code>{}{}</code></td></tr>",
2080-
myitem.visibility.print_with_space(),
2081-
import.print()
2082-
);
2077+
if import.should_be_displayed() {
2078+
write!(
2079+
w,
2080+
"<tr><td><code>{}{}</code></td></tr>",
2081+
myitem.visibility.print_with_space(),
2082+
import.print()
2083+
);
2084+
}
20832085
}
20842086

20852087
_ => {

0 commit comments

Comments
 (0)