From 0e9de930aca7446a23b28c9a286c67d13b5678a3 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Wed, 14 Apr 2021 18:51:54 +0800 Subject: [PATCH 1/3] add macro-or-patterns-2021 test --- src/test/ui/macros/macro-or-patterns-2021.rs | 21 +++++++++++++++ .../ui/macros/macro-or-patterns-2021.stderr | 26 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/test/ui/macros/macro-or-patterns-2021.rs create mode 100644 src/test/ui/macros/macro-or-patterns-2021.stderr 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 0000000000000..edd3f3e7646b8 --- /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 = 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 0000000000000..67feb0c2891f1 --- /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 + From 7b14eda52207a8e17d2e82b915512a232f76bbec Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Wed, 14 Apr 2021 22:16:56 +0800 Subject: [PATCH 2/3] test: add more cases --- ...acro-pat-pattern-followed-by-or-in-2021.rs | 20 ++++++++++++++ ...-pat-pattern-followed-by-or-in-2021.stderr | 26 +++++++++++++++++++ .../macro-pat-pattern-followed-by-or.rs | 20 ++++++++++++++ ...> macro-pat2021-pattern-followed-by-or.rs} | 0 ...cro-pat2021-pattern-followed-by-or.stderr} | 6 ++--- 5 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/macros/macro-pat-pattern-followed-by-or-in-2021.rs create mode 100644 src/test/ui/macros/macro-pat-pattern-followed-by-or-in-2021.stderr create mode 100644 src/test/ui/macros/macro-pat-pattern-followed-by-or.rs rename src/test/ui/macros/{macro-or-patterns-2021.rs => macro-pat2021-pattern-followed-by-or.rs} (100%) rename src/test/ui/macros/{macro-or-patterns-2021.stderr => macro-pat2021-pattern-followed-by-or.stderr} (84%) diff --git a/src/test/ui/macros/macro-pat-pattern-followed-by-or-in-2021.rs b/src/test/ui/macros/macro-pat-pattern-followed-by-or-in-2021.rs new file mode 100644 index 0000000000000..20bfe7d7af704 --- /dev/null +++ b/src/test/ui/macros/macro-pat-pattern-followed-by-or-in-2021.rs @@ -0,0 +1,20 @@ +// edition:2021 +#![allow(unused_macros)] +macro_rules! foo { ($x:pat | $y:pat) => {} } //~ ERROR `$x:pat` is followed by `|`, which is not allowed for `pat` fragments +macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} } //~ ERROR `$x:pat` is followed by `|`, which is not allowed for `pat` fragments +macro_rules! qux { ($x:pat) => {} } // should be ok +macro_rules! match_any { + ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => { //~ ERROR `$pat:pat` may be followed by `|`, which is not allowed for `pat` fragments + match $expr { + $( + $( $pat => $expr_arm, )+ + )+ + } + }; +} + +fn main() { + let result: Result = 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-pat-pattern-followed-by-or-in-2021.stderr b/src/test/ui/macros/macro-pat-pattern-followed-by-or-in-2021.stderr new file mode 100644 index 0000000000000..a5987a25551d2 --- /dev/null +++ b/src/test/ui/macros/macro-pat-pattern-followed-by-or-in-2021.stderr @@ -0,0 +1,26 @@ +error: `$x:pat` is followed by `|`, which is not allowed for `pat` fragments + --> $DIR/macro-pat-pattern-followed-by-or-in-2021.rs:3:28 + | +LL | macro_rules! foo { ($x:pat | $y:pat) => {} } + | ^ not allowed after `pat` fragments + | + = note: allowed there are: `=>`, `,`, `=`, `if` or `in` + +error: `$x:pat` is followed by `|`, which is not allowed for `pat` fragments + --> $DIR/macro-pat-pattern-followed-by-or-in-2021.rs:4:32 + | +LL | macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} } + | ^ not allowed after `pat` fragments + | + = note: allowed there are: `=>`, `,`, `=`, `if` or `in` + +error: `$pat:pat` may be followed by `|`, which is not allowed for `pat` fragments + --> $DIR/macro-pat-pattern-followed-by-or-in-2021.rs:7:36 + | +LL | ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => { + | ^ not allowed after `pat` fragments + | + = note: allowed there are: `=>`, `,`, `=`, `if` or `in` + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/macros/macro-pat-pattern-followed-by-or.rs b/src/test/ui/macros/macro-pat-pattern-followed-by-or.rs new file mode 100644 index 0000000000000..c2658cdbffce9 --- /dev/null +++ b/src/test/ui/macros/macro-pat-pattern-followed-by-or.rs @@ -0,0 +1,20 @@ +// run-pass +#![allow(unused_macros)] +macro_rules! foo { ($x:pat | $y:pat) => {} } // should be ok +macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} } // should be ok +macro_rules! qux { ($x:pat) => {} } // should be ok +macro_rules! match_any { + ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => { // should be ok + match $expr { + $( + $( $pat => $expr_arm, )+ + )+ + } + }; +} + +fn main() { + let result: Result = 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.rs b/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.rs similarity index 100% rename from src/test/ui/macros/macro-or-patterns-2021.rs rename to src/test/ui/macros/macro-pat2021-pattern-followed-by-or.rs diff --git a/src/test/ui/macros/macro-or-patterns-2021.stderr b/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.stderr similarity index 84% rename from src/test/ui/macros/macro-or-patterns-2021.stderr rename to src/test/ui/macros/macro-pat2021-pattern-followed-by-or.stderr index 67feb0c2891f1..fe0b40cd86e12 100644 --- a/src/test/ui/macros/macro-or-patterns-2021.stderr +++ b/src/test/ui/macros/macro-pat2021-pattern-followed-by-or.stderr @@ -1,5 +1,5 @@ error: `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments - --> $DIR/macro-or-patterns-2021.rs:3:32 + --> $DIR/macro-pat2021-pattern-followed-by-or.rs:3:32 | LL | macro_rules! foo { ($x:pat2021 | $y:pat2021) => {} } | ^ not allowed after `pat2021` fragments @@ -7,7 +7,7 @@ LL | macro_rules! foo { ($x:pat2021 | $y:pat2021) => {} } = 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 + --> $DIR/macro-pat2021-pattern-followed-by-or.rs:6:32 | LL | macro_rules! ogg { ($x:pat2021 | $y:pat2015) => {} } | ^ not allowed after `pat2021` fragments @@ -15,7 +15,7 @@ LL | macro_rules! ogg { ($x:pat2021 | $y:pat2015) => {} } = 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 + --> $DIR/macro-pat2021-pattern-followed-by-or.rs:8:40 | LL | ( $expr:expr , $( $( $pat:pat2021 )|+ => $expr_arm:pat2021 ),+ ) => { | ^ not allowed after `pat2021` fragments From eb944c1466c4bfac0315a0f9e7727454147100a4 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Wed, 14 Apr 2021 22:31:44 +0800 Subject: [PATCH 3/3] test: add reasonable case --- src/test/ui/macros/macro-pat-pattern-followed-by-or-in-2021.rs | 2 +- src/test/ui/macros/macro-pat-pattern-followed-by-or.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/ui/macros/macro-pat-pattern-followed-by-or-in-2021.rs b/src/test/ui/macros/macro-pat-pattern-followed-by-or-in-2021.rs index 20bfe7d7af704..f5a97eca21bdb 100644 --- a/src/test/ui/macros/macro-pat-pattern-followed-by-or-in-2021.rs +++ b/src/test/ui/macros/macro-pat-pattern-followed-by-or-in-2021.rs @@ -2,7 +2,7 @@ #![allow(unused_macros)] macro_rules! foo { ($x:pat | $y:pat) => {} } //~ ERROR `$x:pat` is followed by `|`, which is not allowed for `pat` fragments macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} } //~ ERROR `$x:pat` is followed by `|`, which is not allowed for `pat` fragments -macro_rules! qux { ($x:pat) => {} } // should be ok +macro_rules! qux { ($x:pat, $y:pat) => {} } // should be ok macro_rules! match_any { ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => { //~ ERROR `$pat:pat` may be followed by `|`, which is not allowed for `pat` fragments match $expr { diff --git a/src/test/ui/macros/macro-pat-pattern-followed-by-or.rs b/src/test/ui/macros/macro-pat-pattern-followed-by-or.rs index c2658cdbffce9..54bd13d7ebce8 100644 --- a/src/test/ui/macros/macro-pat-pattern-followed-by-or.rs +++ b/src/test/ui/macros/macro-pat-pattern-followed-by-or.rs @@ -2,7 +2,7 @@ #![allow(unused_macros)] macro_rules! foo { ($x:pat | $y:pat) => {} } // should be ok macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} } // should be ok -macro_rules! qux { ($x:pat) => {} } // should be ok +macro_rules! qux { ($x:pat, $y:pat) => {} } // should be ok macro_rules! match_any { ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => { // should be ok match $expr {