Skip to content

Commit

Permalink
Don't allow const to begin a nonterminal
Browse files Browse the repository at this point in the history
  • Loading branch information
camelid authored and Mark-Simulacrum committed Dec 27, 2020
1 parent cebeda3 commit acc2154
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_parse/src/parser/nonterminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
20 changes: 20 additions & 0 deletions src/test/ui/inline-const/macro-with-const.rs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit acc2154

Please sign in to comment.