Skip to content

Commit 15c876d

Browse files
committed
Deduplicate macro_rules! from module_exports when documenting them
This can append if within the same module a `#[macro_export] macro_rules!` is declared but also a reexport of itself producing two export of the same macro in the same module. In that case we only want to document it once.
1 parent eeb16a2 commit 15c876d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/librustdoc/visit_ast.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,21 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
8787
// the rexport defines the path that a user will actually see. Accordingly,
8888
// we add the rexport as an item here, and then skip over the original
8989
// definition in `visit_item()` below.
90+
//
91+
// We also skip `#[macro_export] macro_rules!` that have alredy been inserted,
92+
// this can append if within the same module a `#[macro_export] macro_rules!`
93+
// is declared but also a reexport of itself producing two export of the same
94+
// macro in the same module.
95+
let mut inserted = FxHashSet::default();
9096
for export in self.cx.tcx.module_exports(CRATE_DEF_ID).unwrap_or(&[]) {
9197
if let Res::Def(DefKind::Macro(_), def_id) = export.res {
9298
if let Some(local_def_id) = def_id.as_local() {
9399
if self.cx.tcx.has_attr(def_id, sym::macro_export) {
94-
let hir_id = self.cx.tcx.hir().local_def_id_to_hir_id(local_def_id);
95-
let item = self.cx.tcx.hir().expect_item(hir_id);
96-
top_level_module.items.push((item, None));
100+
if !inserted.insert(def_id) {
101+
let hir_id = self.cx.tcx.hir().local_def_id_to_hir_id(local_def_id);
102+
let item = self.cx.tcx.hir().expect_item(hir_id);
103+
top_level_module.items.push((item, None));
104+
}
97105
}
98106
}
99107
}

0 commit comments

Comments
 (0)