mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Macros: match const { ... } with expr nonterminal in edition 2024
Co-authored-by: Eric Holk <eric@theincredibleholk.org> Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
parent
73303c3b45
commit
a55d06323a
@ -3,6 +3,7 @@ use rustc_ast::token::{self, Delimiter, Nonterminal, Nonterminal::*, Nonterminal
|
|||||||
use rustc_ast::HasTokens;
|
use rustc_ast::HasTokens;
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_errors::PResult;
|
use rustc_errors::PResult;
|
||||||
|
use rustc_span::edition::Edition;
|
||||||
use rustc_span::symbol::{kw, Ident};
|
use rustc_span::symbol::{kw, Ident};
|
||||||
|
|
||||||
use crate::errors::UnexpectedNonterminal;
|
use crate::errors::UnexpectedNonterminal;
|
||||||
@ -37,13 +38,19 @@ impl<'a> Parser<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match kind {
|
match kind {
|
||||||
NonterminalKind::Expr | NonterminalKind::Expr2021 => {
|
NonterminalKind::Expr2021 => {
|
||||||
token.can_begin_expr()
|
token.can_begin_expr()
|
||||||
// This exception is here for backwards compatibility.
|
// This exception is here for backwards compatibility.
|
||||||
&& !token.is_keyword(kw::Let)
|
&& !token.is_keyword(kw::Let)
|
||||||
// This exception is here for backwards compatibility.
|
// This exception is here for backwards compatibility.
|
||||||
&& !token.is_keyword(kw::Const)
|
&& !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() >= Edition::Edition2024 || !token.is_keyword(kw::Const))
|
||||||
|
}
|
||||||
NonterminalKind::Ty => token.can_begin_type(),
|
NonterminalKind::Ty => token.can_begin_type(),
|
||||||
NonterminalKind::Ident => get_macro_ident(token).is_some(),
|
NonterminalKind::Ident => get_macro_ident(token).is_some(),
|
||||||
NonterminalKind::Literal => token.can_begin_literal_maybe_minus(),
|
NonterminalKind::Literal => token.can_begin_literal_maybe_minus(),
|
||||||
|
32
tests/ui/macros/expr_2021_inline_const.edi2021.stderr
Normal file
32
tests/ui/macros/expr_2021_inline_const.edi2021.stderr
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
error: no rules expected the token `const`
|
||||||
|
--> $DIR/expr_2021_inline_const.rs:21:12
|
||||||
|
|
|
||||||
|
LL | macro_rules! m2021 {
|
||||||
|
| ------------------ when calling this macro
|
||||||
|
...
|
||||||
|
LL | m2021!(const { 1 });
|
||||||
|
| ^^^^^ no rules expected this token in macro call
|
||||||
|
|
|
||||||
|
note: while trying to match meta-variable `$e:expr_2021`
|
||||||
|
--> $DIR/expr_2021_inline_const.rs:10:6
|
||||||
|
|
|
||||||
|
LL | ($e:expr_2021) => {
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: no rules expected the token `const`
|
||||||
|
--> $DIR/expr_2021_inline_const.rs:22:12
|
||||||
|
|
|
||||||
|
LL | macro_rules! m2024 {
|
||||||
|
| ------------------ when calling this macro
|
||||||
|
...
|
||||||
|
LL | m2024!(const { 1 });
|
||||||
|
| ^^^^^ no rules expected this token in macro call
|
||||||
|
|
|
||||||
|
note: while trying to match meta-variable `$e:expr`
|
||||||
|
--> $DIR/expr_2021_inline_const.rs:16:6
|
||||||
|
|
|
||||||
|
LL | ($e:expr) => {
|
||||||
|
| ^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
17
tests/ui/macros/expr_2021_inline_const.edi2024.stderr
Normal file
17
tests/ui/macros/expr_2021_inline_const.edi2024.stderr
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
error: no rules expected the token `const`
|
||||||
|
--> $DIR/expr_2021_inline_const.rs:21:12
|
||||||
|
|
|
||||||
|
LL | macro_rules! m2021 {
|
||||||
|
| ------------------ when calling this macro
|
||||||
|
...
|
||||||
|
LL | m2021!(const { 1 });
|
||||||
|
| ^^^^^ no rules expected this token in macro call
|
||||||
|
|
|
||||||
|
note: while trying to match meta-variable `$e:expr_2021`
|
||||||
|
--> $DIR/expr_2021_inline_const.rs:10:6
|
||||||
|
|
|
||||||
|
LL | ($e:expr_2021) => {
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
23
tests/ui/macros/expr_2021_inline_const.rs
Normal file
23
tests/ui/macros/expr_2021_inline_const.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
//@ revisions: edi2021 edi2024
|
||||||
|
//@[edi2024]compile-flags: --edition=2024 -Z unstable-options
|
||||||
|
//@[edi2021]compile-flags: --edition=2021
|
||||||
|
|
||||||
|
// This test ensures that the inline const match only on edition 2024
|
||||||
|
#![feature(expr_fragment_specifier_2024)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
macro_rules! m2021 {
|
||||||
|
($e:expr_2021) => {
|
||||||
|
$e
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! m2024 {
|
||||||
|
($e:expr) => {
|
||||||
|
$e
|
||||||
|
};
|
||||||
|
}
|
||||||
|
fn main() {
|
||||||
|
m2021!(const { 1 }); //~ ERROR: no rules expected the token `const`
|
||||||
|
m2024!(const { 1 }); //[edi2021]~ ERROR: no rules expected the token `const`
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user