diff options
| author | Camelid <camelidcamel@gmail.com> | 2020-12-17 13:51:20 -0800 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2020-12-27 12:26:00 -0500 |
| commit | acc2154a7c3d842a82a19867e9070989748d2667 (patch) | |
| tree | b6b2d4a327f8c368310deda270a1506a5aa42097 | |
| parent | cebeda351ee8f25bc7d5f45506bd7e1efc8c1fbd (diff) | |
| download | rust-acc2154a7c3d842a82a19867e9070989748d2667.tar.gz rust-acc2154a7c3d842a82a19867e9070989748d2667.zip | |
Don't allow `const` to begin a nonterminal
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
| -rw-r--r-- | compiler/rustc_parse/src/parser/nonterminal.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/inline-const/macro-with-const.rs | 20 |
2 files changed, 22 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index ab88362dad9..38f04da0395 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -27,6 +27,8 @@ impl<'a> Parser<'a> { token.can_begin_expr() // This exception is here for backwards compatibility. && !token.is_keyword(kw::Let) + // This exception is here for backwards compatibility. + && !token.is_keyword(kw::Const) } NonterminalKind::Ty => token.can_begin_type(), NonterminalKind::Ident => get_macro_ident(token).is_some(), diff --git a/src/test/ui/inline-const/macro-with-const.rs b/src/test/ui/inline-const/macro-with-const.rs new file mode 100644 index 00000000000..e7393166d8d --- /dev/null +++ b/src/test/ui/inline-const/macro-with-const.rs @@ -0,0 +1,20 @@ +// check-pass + +macro_rules! exp { + (const $n:expr) => { + $n + }; +} + +macro_rules! stmt { + (exp $e:expr) => { + $e + }; + (exp $($t:tt)+) => { + exp!($($t)+) + }; +} + +fn main() { + stmt!(exp const 1); +} |
