about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLoïc BRANSTETT <loic.branstett@epitech.eu>2021-10-14 01:50:37 +0200
committerPietro Albini <pietro.albini@ferrous-systems.com>2021-10-18 10:47:29 +0200
commitaef5765479b7c7d3d44fc69c8126b2ef5052433f (patch)
tree13ad2379de9f507fc29b43a693373126cdb128fb
parent3197652fbe20367c9acdda2f6878c56fd5a362ce (diff)
downloadrust-aef5765479b7c7d3d44fc69c8126b2ef5052433f.tar.gz
rust-aef5765479b7c7d3d44fc69c8126b2ef5052433f.zip
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.
-rw-r--r--src/librustdoc/visit_ast.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs
index 897b9140fc8..7182310b73a 100644
--- a/src/librustdoc/visit_ast.rs
+++ b/src/librustdoc/visit_ast.rs
@@ -86,13 +86,21 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
         // the rexport defines the path that a user will actually see. Accordingly,
         // we add the rexport as an item here, and then skip over the original
         // definition in `visit_item()` below.
+        //
+        // We also skip `#[macro_export] macro_rules!` that have alredy been inserted,
+        // 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.
+        let mut inserted = FxHashSet::default();
         for export in self.cx.tcx.module_exports(CRATE_DEF_ID).unwrap_or(&[]) {
             if let Res::Def(DefKind::Macro(_), def_id) = export.res {
                 if let Some(local_def_id) = def_id.as_local() {
                     if self.cx.tcx.has_attr(def_id, sym::macro_export) {
-                        let hir_id = self.cx.tcx.hir().local_def_id_to_hir_id(local_def_id);
-                        let item = self.cx.tcx.hir().expect_item(hir_id);
-                        top_level_module.items.push((item, None));
+                        if !inserted.insert(def_id) {
+                            let hir_id = self.cx.tcx.hir().local_def_id_to_hir_id(local_def_id);
+                            let item = self.cx.tcx.hir().expect_item(hir_id);
+                            top_level_module.items.push((item, None));
+                        }
                     }
                 }
             }