about summary refs log tree commit diff
diff options
context:
space:
mode:
authorhi-rustin <rustin.liu@gmail.com>2021-04-14 18:51:54 +0800
committerhi-rustin <rustin.liu@gmail.com>2021-04-14 18:51:54 +0800
commit0e9de930aca7446a23b28c9a286c67d13b5678a3 (patch)
tree15586554c774ab10454a3064cc886c7c0f1bdcaf
parent132b4e5d167b7e622fcc11fa2b67b931105b4de1 (diff)
add macro-or-patterns-2021 test
-rw-r--r--src/test/ui/macros/macro-or-patterns-2021.rs21
-rw-r--r--src/test/ui/macros/macro-or-patterns-2021.stderr26
2 files changed, 47 insertions, 0 deletions
diff --git a/src/test/ui/macros/macro-or-patterns-2021.rs b/src/test/ui/macros/macro-or-patterns-2021.rs
new file mode 100644
index 00000000000..edd3f3e7646
--- /dev/null
+++ b/src/test/ui/macros/macro-or-patterns-2021.rs
@@ -0,0 +1,21 @@
+#![feature(edition_macro_pats)]
+#![allow(unused_macros)]
+macro_rules! foo { ($x:pat2021 | $y:pat2021) => {} } //~ ERROR `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments
+macro_rules! baz { ($x:pat2015 | $y:pat2015) => {} } // should be ok
+macro_rules! qux { ($x:pat2015 | $y:pat2021) => {} } // should be ok
+macro_rules! ogg { ($x:pat2021 | $y:pat2015) => {} } //~ ERROR `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments
+macro_rules! match_any {
+    ( $expr:expr , $( $( $pat:pat2021 )|+ => $expr_arm:pat2021 ),+ ) => { //~ ERROR  `$pat:pat2021` may be followed by `|`, which is not allowed for `pat2021` fragments
+        match $expr {
+            $(
+                $( $pat => $expr_arm, )+
+            )+
+        }
+    };
+}
+
+fn main() {
+    let result: Result<i64, i32> = Err(42);
+    let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into());
+    assert_eq!(int, 42);
+}
diff --git a/src/test/ui/macros/macro-or-patterns-2021.stderr b/src/test/ui/macros/macro-or-patterns-2021.stderr
new file mode 100644
index 00000000000..67feb0c2891
--- /dev/null
+++ b/src/test/ui/macros/macro-or-patterns-2021.stderr
@@ -0,0 +1,26 @@
+error: `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments
+  --> $DIR/macro-or-patterns-2021.rs:3:32
+   |
+LL | macro_rules! foo { ($x:pat2021 | $y:pat2021) => {} }
+   |                                ^ not allowed after `pat2021` fragments
+   |
+   = note: allowed there are: `=>`, `,`, `=`, `if` or `in`
+
+error: `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments
+  --> $DIR/macro-or-patterns-2021.rs:6:32
+   |
+LL | macro_rules! ogg { ($x:pat2021 | $y:pat2015) => {} }
+   |                                ^ not allowed after `pat2021` fragments
+   |
+   = note: allowed there are: `=>`, `,`, `=`, `if` or `in`
+
+error: `$pat:pat2021` may be followed by `|`, which is not allowed for `pat2021` fragments
+  --> $DIR/macro-or-patterns-2021.rs:8:40
+   |
+LL |     ( $expr:expr , $( $( $pat:pat2021 )|+ => $expr_arm:pat2021 ),+ ) => {
+   |                                        ^ not allowed after `pat2021` fragments
+   |
+   = note: allowed there are: `=>`, `,`, `=`, `if` or `in`
+
+error: aborting due to 3 previous errors
+