Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect gating of nonterminals in key-value attributes #85445

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
30 changes: 30 additions & 0 deletions src/test/ui/macros/issue-85432-ungated-attr-macro.rs
Original file line number Diff line number Diff line change
@@ -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() {}