Skip to content

Commit 9269995

Browse files
authored
Rollup merge of #80135 - camelid:const-macro-nt, r=petrochenkov
Don't allow `const` to begin a nonterminal Fixes #79908. Thanks to Vadim Petrochenkov who [told me what the fix was][z]! [z]: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/finding.20which.20macro.20rule.20to.20use/near/220240422 r? ``@petrochenkov``
2 parents 5eb1526 + d6f1787 commit 9269995

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

compiler/rustc_parse/src/parser/nonterminal.rs

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ impl<'a> Parser<'a> {
2727
token.can_begin_expr()
2828
// This exception is here for backwards compatibility.
2929
&& !token.is_keyword(kw::Let)
30+
// This exception is here for backwards compatibility.
31+
&& !token.is_keyword(kw::Const)
3032
}
3133
NonterminalKind::Ty => token.can_begin_type(),
3234
NonterminalKind::Ident => get_macro_ident(token).is_some(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// check-pass
2+
3+
macro_rules! exp {
4+
(const $n:expr) => {
5+
$n
6+
};
7+
}
8+
9+
macro_rules! stmt {
10+
(exp $e:expr) => {
11+
$e
12+
};
13+
(exp $($t:tt)+) => {
14+
exp!($($t)+)
15+
};
16+
}
17+
18+
fn main() {
19+
stmt!(exp const 1);
20+
}

0 commit comments

Comments
 (0)