diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 35cfaae13a4a0..5f66f9b176db9 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -1078,7 +1078,10 @@ impl<'a> Parser<'a> { match &expr.kind { // Not gated to support things like `doc = $expr` that work on stable. - _ if is_interpolated_expr => {} + // Do not gate in `capture_cfg` mode, since we flatten all nontemrinals + // before parsing. `capture_cfg` mode is only used to reparse existing + // tokens, so the gating will be performed by the initial parse + _ if is_interpolated_expr || self.capture_cfg => {} ExprKind::Lit(lit) if lit.kind.is_unsuffixed() => {} _ => self.sess.gated_spans.gate(sym::extended_key_value_attributes, span), } diff --git a/src/test/ui/macros/issue-85432-ungated-attr-macro.rs b/src/test/ui/macros/issue-85432-ungated-attr-macro.rs new file mode 100644 index 0000000000000..bac124c6f4c3c --- /dev/null +++ b/src/test/ui/macros/issue-85432-ungated-attr-macro.rs @@ -0,0 +1,30 @@ +// check-pass +// Regression test for issue #85432 +// Ensures that we don't incorrectly gate nonterminals +// in key-value macros when we need to reparse due to +// the presence of `#[derive]` + +macro_rules! with_doc_comment { + ($comment:expr, $item:item) => { + #[doc = $comment] + $item + }; +} + +macro_rules! database_table_doc { + () => { + "" + }; +} + +with_doc_comment! { + database_table_doc!(), + #[derive(Debug)] + struct Image { + #[cfg(FALSE)] + _f: (), + } + +} + +fn main() {}