]> git.lizzy.rs Git - rust.git/commitdiff
Deduplicate macro_rules! from module_exports when documenting them
authorLoïc BRANSTETT <loic.branstett@epitech.eu>
Wed, 13 Oct 2021 23:50:37 +0000 (01:50 +0200)
committerLoïc BRANSTETT <loic.branstett@epitech.eu>
Wed, 13 Oct 2021 23:51:35 +0000 (01:51 +0200)
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.

src/librustdoc/visit_ast.rs

index 36b1a14f6c1ea488f0d26af3316584a9373ff7e2..3e38ac822f50ad74449c744409cc41169b39f496 100644 (file)
@@ -87,13 +87,21 @@ fn store_path(&mut self, did: DefId) {
         // 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));
+                        }
                     }
                 }
             }