From 65da4adfcd12a062874524a37ebd4f522c04205f Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Fri, 12 Apr 2024 10:28:03 -0700 Subject: [PATCH] Add test that expr_2021 only works on 2024 edition Co-authored-by: Vincenzo Palazzo --- tests/ui/macros/expr_2021_old_edition.rs | 13 ++++++++++ tests/ui/macros/expr_2021_old_edition.stderr | 25 ++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/ui/macros/expr_2021_old_edition.rs create mode 100644 tests/ui/macros/expr_2021_old_edition.stderr diff --git a/tests/ui/macros/expr_2021_old_edition.rs b/tests/ui/macros/expr_2021_old_edition.rs new file mode 100644 index 000000000000..329c5cdca335 --- /dev/null +++ b/tests/ui/macros/expr_2021_old_edition.rs @@ -0,0 +1,13 @@ +//@ compile-flags: --edition=2021 + +// This test ensures that expr_2021 is not allowed on pre-2024 editions + +macro_rules! m { + ($e:expr_2021) => { //~ ERROR: invalid fragment specifier `expr_2021` + $e + }; +} + +fn main() { + m!(()); //~ ERROR: no rules expected the token `(` +} diff --git a/tests/ui/macros/expr_2021_old_edition.stderr b/tests/ui/macros/expr_2021_old_edition.stderr new file mode 100644 index 000000000000..b5934fb3361b --- /dev/null +++ b/tests/ui/macros/expr_2021_old_edition.stderr @@ -0,0 +1,25 @@ +error: invalid fragment specifier `expr_2021` + --> $DIR/expr_2021_old_edition.rs:6:6 + | +LL | ($e:expr_2021) => { + | ^^^^^^^^^^^^ + | + = help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis` + +error: no rules expected the token `(` + --> $DIR/expr_2021_old_edition.rs:12:8 + | +LL | macro_rules! m { + | -------------- when calling this macro +... +LL | m!(()); + | ^ no rules expected this token in macro call + | +note: while trying to match meta-variable `$e:ident` + --> $DIR/expr_2021_old_edition.rs:6:6 + | +LL | ($e:expr_2021) => { + | ^^^^^^^^^^^^ + +error: aborting due to 2 previous errors +