Skip to content

Commit fd1e19e

Browse files
committed
Fix incorrect gating of nonterminals in key-value attributes
Fixes rust-lang#85432 When processing a `#[derive]` or `#[cfg_eval]` attribute, we need to re-parse our attribute target, which requires flattenting all `Nonterminals`. However, this caused us to incorrectly gate on a (flattented) nonterminal in a key-value attribute, which is supposed to be allowed. Since we already perform this gating during the initial parse, we suppress it in `capture_cfg` mode.
1 parent a5560a6 commit fd1e19e

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

compiler/rustc_parse/src/parser/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,10 @@ impl<'a> Parser<'a> {
10781078

10791079
match &expr.kind {
10801080
// Not gated to support things like `doc = $expr` that work on stable.
1081-
_ if is_interpolated_expr => {}
1081+
// Do not gate in `capture_cfg` mode, since we flatten all nontemrinals
1082+
// before parsing. `capture_cfg` mode is only used to reparse existing
1083+
// tokens, so the gating will be performed by the initial parse
1084+
_ if is_interpolated_expr || self.capture_cfg => {}
10821085
ExprKind::Lit(lit) if lit.kind.is_unsuffixed() => {}
10831086
_ => self.sess.gated_spans.gate(sym::extended_key_value_attributes, span),
10841087
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// check-pass
2+
// Regression test for issue #85432
3+
// Ensures that we don't incorrectly gate nonterminals
4+
// in key-value macros when we need to reparse due to
5+
// the presence of `#[derive]`
6+
7+
macro_rules! with_doc_comment {
8+
($comment:expr, $item:item) => {
9+
#[doc = $comment]
10+
$item
11+
};
12+
}
13+
14+
macro_rules! database_table_doc {
15+
() => {
16+
""
17+
};
18+
}
19+
20+
with_doc_comment! {
21+
database_table_doc!(),
22+
#[derive(Debug)]
23+
struct Image {
24+
#[cfg(FALSE)]
25+
_f: (),
26+
}
27+
28+
}
29+
30+
fn main() {}

0 commit comments

Comments
 (0)