Add expr_2021 nonterminal and feature flag

This commit adds a new nonterminal `expr_2021` in macro patterns, and
`expr_fragment_specifier_2024` feature flag. For now, `expr` and
`expr_2021` are treated the same, but in future PRs we will update
`expr` to match to new grammar.

Co-authored-by: Vincezo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
Eric Holk 2024-04-12 10:19:23 -07:00
parent 030a12ce2b
commit ef6478ba5f
No known key found for this signature in database
GPG key ID: 8EA6B43ED4CE0911
10 changed files with 48 additions and 3 deletions

View file

@ -433,3 +433,10 @@ pub struct ExpectedParenOrBrace<'a> {
pub span: Span,
pub token: Cow<'a, str>,
}
#[derive(Diagnostic)]
#[diag(expand_expr_2021_is_experimental)]
pub struct Expr2021IsExperimental {
#[primary_span]
pub span: Span,
}

View file

@ -1290,7 +1290,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow {
// maintain
IsInFollow::Yes
}
NonterminalKind::Stmt | NonterminalKind::Expr => {
NonterminalKind::Stmt | NonterminalKind::Expr | NonterminalKind::Expr2021 => {
const TOKENS: &[&str] = &["`=>`", "`,`", "`;`"];
match tok {
TokenTree::Token(token) => match token.kind {

View file

@ -92,6 +92,12 @@ pub(super) fn parse(
token::NonterminalKind::Ident
},
);
if kind == token::NonterminalKind::Expr2021
&& !features.expr_fragment_specifier_2024
{
sess.dcx()
.emit_err(errors::Expr2021IsExperimental { span });
}
result.push(TokenTree::MetaVarDecl(span, ident, Some(kind)));
continue;
}