Auto merge of #123865 - eholk:expr_2021, r=fmease
Update `expr` matcher for Edition 2024 and add `expr_2021` nonterminal This commit adds a new nonterminal `expr_2021` in macro patterns, and `expr_fragment_specifier_2024` feature flag. This change also updates `expr` so that on Edition 2024 it will also match `const { ... }` blocks, while `expr_2021` preserves the current behavior of `expr`, matching expressions without `const` blocks. Joint work with `@vincenzopalazzo.` Issue #123742
This commit is contained in:
commit
9b75a43881
13 changed files with 204 additions and 24 deletions
|
@ -36,13 +36,19 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
match kind {
|
||||
NonterminalKind::Expr => {
|
||||
NonterminalKind::Expr2021 => {
|
||||
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::Expr => {
|
||||
token.can_begin_expr()
|
||||
// This exception is here for backwards compatibility.
|
||||
&& !token.is_keyword(kw::Let)
|
||||
&& (token.span.edition().at_least_rust_2024() || !token.is_keyword(kw::Const))
|
||||
}
|
||||
NonterminalKind::Ty => token.can_begin_type(),
|
||||
NonterminalKind::Ident => get_macro_ident(token).is_some(),
|
||||
NonterminalKind::Literal => token.can_begin_literal_maybe_minus(),
|
||||
|
@ -143,7 +149,9 @@ impl<'a> Parser<'a> {
|
|||
})?)
|
||||
}
|
||||
|
||||
NonterminalKind::Expr => NtExpr(self.parse_expr_force_collect()?),
|
||||
NonterminalKind::Expr | NonterminalKind::Expr2021 => {
|
||||
NtExpr(self.parse_expr_force_collect()?)
|
||||
}
|
||||
NonterminalKind::Literal => {
|
||||
// The `:literal` matcher does not support attributes
|
||||
NtLiteral(self.collect_tokens_no_attrs(|this| this.parse_literal_maybe_minus())?)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue