From aa76e135ff5777b32a20cdf9407564322b4b422d Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Sun, 28 Aug 2022 01:20:26 +0900 Subject: [PATCH] extend attrs if local_def_id exists --- src/librustdoc/passes/propagate_doc_cfg.rs | 5 +++-- src/test/rustdoc-ui/issue-101076.rs | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 src/test/rustdoc-ui/issue-101076.rs diff --git a/src/librustdoc/passes/propagate_doc_cfg.rs b/src/librustdoc/passes/propagate_doc_cfg.rs index 21d295bb1f88e..2b12d118bca0e 100644 --- a/src/librustdoc/passes/propagate_doc_cfg.rs +++ b/src/librustdoc/passes/propagate_doc_cfg.rs @@ -41,8 +41,9 @@ impl<'a, 'tcx> DocFolder for CfgPropagator<'a, 'tcx> { if self.parent != Some(expected_parent) { let mut attrs = Vec::new(); for (parent_hir_id, _) in hir.parent_iter(hir_id) { - let def_id = hir.local_def_id(parent_hir_id).to_def_id(); - attrs.extend_from_slice(load_attrs(self.cx, def_id)); + if let Some(def_id) = hir.opt_local_def_id(parent_hir_id) { + attrs.extend_from_slice(load_attrs(self.cx, def_id.to_def_id())); + } } let (_, cfg) = merge_attrs(self.cx, None, item.attrs.other_attrs.as_slice(), Some(&attrs)); diff --git a/src/test/rustdoc-ui/issue-101076.rs b/src/test/rustdoc-ui/issue-101076.rs new file mode 100644 index 0000000000000..648f9902908af --- /dev/null +++ b/src/test/rustdoc-ui/issue-101076.rs @@ -0,0 +1,14 @@ +// check-pass + +const _: () = { + #[macro_export] + macro_rules! first_macro { + () => {} + } + mod foo { + #[macro_export] + macro_rules! second_macro { + () => {} + } + } +};