Skip to content

Commit aef5765

Browse files
Urgaupietroalbini
authored andcommitted
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 3197652 commit aef5765

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

0 commit comments

Comments
 (0)