Skip to content

Commit 0e9de93

Browse files
committed
add macro-or-patterns-2021 test
1 parent 132b4e5 commit 0e9de93

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![feature(edition_macro_pats)]
2+
#![allow(unused_macros)]
3+
macro_rules! foo { ($x:pat2021 | $y:pat2021) => {} } //~ ERROR `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments
4+
macro_rules! baz { ($x:pat2015 | $y:pat2015) => {} } // should be ok
5+
macro_rules! qux { ($x:pat2015 | $y:pat2021) => {} } // should be ok
6+
macro_rules! ogg { ($x:pat2021 | $y:pat2015) => {} } //~ ERROR `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments
7+
macro_rules! match_any {
8+
( $expr:expr , $( $( $pat:pat2021 )|+ => $expr_arm:pat2021 ),+ ) => { //~ ERROR `$pat:pat2021` may be followed by `|`, which is not allowed for `pat2021` fragments
9+
match $expr {
10+
$(
11+
$( $pat => $expr_arm, )+
12+
)+
13+
}
14+
};
15+
}
16+
17+
fn main() {
18+
let result: Result<i64, i32> = Err(42);
19+
let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into());
20+
assert_eq!(int, 42);
21+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments
2+
--> $DIR/macro-or-patterns-2021.rs:3:32
3+
|
4+
LL | macro_rules! foo { ($x:pat2021 | $y:pat2021) => {} }
5+
| ^ not allowed after `pat2021` fragments
6+
|
7+
= note: allowed there are: `=>`, `,`, `=`, `if` or `in`
8+
9+
error: `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments
10+
--> $DIR/macro-or-patterns-2021.rs:6:32
11+
|
12+
LL | macro_rules! ogg { ($x:pat2021 | $y:pat2015) => {} }
13+
| ^ not allowed after `pat2021` fragments
14+
|
15+
= note: allowed there are: `=>`, `,`, `=`, `if` or `in`
16+
17+
error: `$pat:pat2021` may be followed by `|`, which is not allowed for `pat2021` fragments
18+
--> $DIR/macro-or-patterns-2021.rs:8:40
19+
|
20+
LL | ( $expr:expr , $( $( $pat:pat2021 )|+ => $expr_arm:pat2021 ),+ ) => {
21+
| ^ not allowed after `pat2021` fragments
22+
|
23+
= note: allowed there are: `=>`, `,`, `=`, `if` or `in`
24+
25+
error: aborting due to 3 previous errors
26+

0 commit comments

Comments
 (0)