From 568e78f36653b6c336a278e252cc08d2088937c0 Mon Sep 17 00:00:00 2001
From: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Date: Sat, 25 May 2024 10:50:25 +0200
Subject: [PATCH] tests: adds cargo fix tests

Co-Developed-by: Eric Holk
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
---
 .../macros/expr_2021_cargo_fix_edition.fixed  | 24 ++++++++++++++
 .../ui/macros/expr_2021_cargo_fix_edition.rs  | 24 ++++++++++++++
 .../macros/expr_2021_cargo_fix_edition.stderr | 33 +++++++++++++++++++
 .../expr_2021_inline_const.edi2021.stderr     |  4 +--
 .../expr_2021_inline_const.edi2024.stderr     |  2 +-
 tests/ui/macros/expr_2021_inline_const.rs     |  7 ++++
 6 files changed, 91 insertions(+), 3 deletions(-)
 create mode 100644 tests/ui/macros/expr_2021_cargo_fix_edition.fixed
 create mode 100644 tests/ui/macros/expr_2021_cargo_fix_edition.rs
 create mode 100644 tests/ui/macros/expr_2021_cargo_fix_edition.stderr

diff --git a/tests/ui/macros/expr_2021_cargo_fix_edition.fixed b/tests/ui/macros/expr_2021_cargo_fix_edition.fixed
new file mode 100644
index 00000000000..1becd8a92d6
--- /dev/null
+++ b/tests/ui/macros/expr_2021_cargo_fix_edition.fixed
@@ -0,0 +1,24 @@
+//@ run-rustfix
+//@ check-pass
+//@ compile-flags: --edition=2021
+#![allow(incomplete_features)]
+#![feature(expr_fragment_specifier_2024)]
+#![warn(edition_2024_expr_fragment_specifier)]
+
+macro_rules! m {
+    ($e:expr_2021) => { //~ WARN: the `expr` fragment specifier will accept more expressions in the 2024 edition
+       //~^ WARN: this changes meaning in Rust 2024
+        $e
+    };
+    ($($i:expr_2021)*) => { }; //~ WARN: the `expr` fragment specifier will accept more expressions in the 2024 edition
+       //~^ WARN: this changes meaning in Rust 2024
+}
+
+macro_rules! test {
+    (expr) => {}
+}
+
+fn main() {
+    m!(());
+    test!(expr);
+}
diff --git a/tests/ui/macros/expr_2021_cargo_fix_edition.rs b/tests/ui/macros/expr_2021_cargo_fix_edition.rs
new file mode 100644
index 00000000000..ec0b86d2c23
--- /dev/null
+++ b/tests/ui/macros/expr_2021_cargo_fix_edition.rs
@@ -0,0 +1,24 @@
+//@ run-rustfix
+//@ check-pass
+//@ compile-flags: --edition=2021
+#![allow(incomplete_features)]
+#![feature(expr_fragment_specifier_2024)]
+#![warn(edition_2024_expr_fragment_specifier)]
+
+macro_rules! m {
+    ($e:expr) => { //~ WARN: the `expr` fragment specifier will accept more expressions in the 2024 edition
+       //~^ WARN: this changes meaning in Rust 2024
+        $e
+    };
+    ($($i:expr)*) => { }; //~ WARN: the `expr` fragment specifier will accept more expressions in the 2024 edition
+       //~^ WARN: this changes meaning in Rust 2024
+}
+
+macro_rules! test {
+    (expr) => {}
+}
+
+fn main() {
+    m!(());
+    test!(expr);
+}
diff --git a/tests/ui/macros/expr_2021_cargo_fix_edition.stderr b/tests/ui/macros/expr_2021_cargo_fix_edition.stderr
new file mode 100644
index 00000000000..e8a44fed322
--- /dev/null
+++ b/tests/ui/macros/expr_2021_cargo_fix_edition.stderr
@@ -0,0 +1,33 @@
+warning: the `expr` fragment specifier will accept more expressions in the 2024 edition
+  --> $DIR/expr_2021_cargo_fix_edition.rs:9:9
+   |
+LL |     ($e:expr) => {
+   |         ^^^^
+   |
+   = warning: this changes meaning in Rust 2024
+   = note: for more information, see Migration Guide <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/macro-fragment-specifiers.html>
+note: the lint level is defined here
+  --> $DIR/expr_2021_cargo_fix_edition.rs:6:9
+   |
+LL | #![warn(edition_2024_expr_fragment_specifier)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: to keep the existing behavior, use the `expr_2021` fragment specifier
+   |
+LL |     ($e:expr_2021) => {
+   |         ~~~~~~~~~
+
+warning: the `expr` fragment specifier will accept more expressions in the 2024 edition
+  --> $DIR/expr_2021_cargo_fix_edition.rs:13:11
+   |
+LL |     ($($i:expr)*) => { };
+   |           ^^^^
+   |
+   = warning: this changes meaning in Rust 2024
+   = note: for more information, see Migration Guide <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/macro-fragment-specifiers.html>
+help: to keep the existing behavior, use the `expr_2021` fragment specifier
+   |
+LL |     ($($i:expr_2021)*) => { };
+   |           ~~~~~~~~~
+
+warning: 2 warnings emitted
+
diff --git a/tests/ui/macros/expr_2021_inline_const.edi2021.stderr b/tests/ui/macros/expr_2021_inline_const.edi2021.stderr
index 5e880964454..b55ae62030c 100644
--- a/tests/ui/macros/expr_2021_inline_const.edi2021.stderr
+++ b/tests/ui/macros/expr_2021_inline_const.edi2021.stderr
@@ -1,5 +1,5 @@
 error: no rules expected the token `const`
-  --> $DIR/expr_2021_inline_const.rs:21:12
+  --> $DIR/expr_2021_inline_const.rs:26:12
    |
 LL | macro_rules! m2021 {
    | ------------------ when calling this macro
@@ -14,7 +14,7 @@ LL |     ($e:expr_2021) => {
    |      ^^^^^^^^^^^^
 
 error: no rules expected the token `const`
-  --> $DIR/expr_2021_inline_const.rs:22:12
+  --> $DIR/expr_2021_inline_const.rs:27:12
    |
 LL | macro_rules! m2024 {
    | ------------------ when calling this macro
diff --git a/tests/ui/macros/expr_2021_inline_const.edi2024.stderr b/tests/ui/macros/expr_2021_inline_const.edi2024.stderr
index 237ecb2cc19..285db53d6c8 100644
--- a/tests/ui/macros/expr_2021_inline_const.edi2024.stderr
+++ b/tests/ui/macros/expr_2021_inline_const.edi2024.stderr
@@ -1,5 +1,5 @@
 error: no rules expected the token `const`
-  --> $DIR/expr_2021_inline_const.rs:21:12
+  --> $DIR/expr_2021_inline_const.rs:26:12
    |
 LL | macro_rules! m2021 {
    | ------------------ when calling this macro
diff --git a/tests/ui/macros/expr_2021_inline_const.rs b/tests/ui/macros/expr_2021_inline_const.rs
index ebc5ea36421..06b74a466d6 100644
--- a/tests/ui/macros/expr_2021_inline_const.rs
+++ b/tests/ui/macros/expr_2021_inline_const.rs
@@ -17,7 +17,14 @@ macro_rules! m2024 {
         $e
     };
 }
+
+macro_rules! test {
+    (expr) => {}
+}
+
 fn main() {
     m2021!(const { 1 }); //~ ERROR: no rules expected the token `const`
     m2024!(const { 1 }); //[edi2021]~ ERROR: no rules expected the token `const`
+
+    test!(expr);
 }