Skip to content

Commit 7b14eda

Browse files
committed
test: add more cases
1 parent 0e9de93 commit 7b14eda

5 files changed

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

src/test/ui/macros/macro-or-patterns-2021.stderr renamed to src/test/ui/macros/macro-pat2021-pattern-followed-by-or.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
error: `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments
2-
--> $DIR/macro-or-patterns-2021.rs:3:32
2+
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:3:32
33
|
44
LL | macro_rules! foo { ($x:pat2021 | $y:pat2021) => {} }
55
| ^ not allowed after `pat2021` fragments
66
|
77
= note: allowed there are: `=>`, `,`, `=`, `if` or `in`
88

99
error: `$x:pat2021` is followed by `|`, which is not allowed for `pat2021` fragments
10-
--> $DIR/macro-or-patterns-2021.rs:6:32
10+
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:6:32
1111
|
1212
LL | macro_rules! ogg { ($x:pat2021 | $y:pat2015) => {} }
1313
| ^ not allowed after `pat2021` fragments
1414
|
1515
= note: allowed there are: `=>`, `,`, `=`, `if` or `in`
1616

1717
error: `$pat:pat2021` may be followed by `|`, which is not allowed for `pat2021` fragments
18-
--> $DIR/macro-or-patterns-2021.rs:8:40
18+
--> $DIR/macro-pat2021-pattern-followed-by-or.rs:8:40
1919
|
2020
LL | ( $expr:expr , $( $( $pat:pat2021 )|+ => $expr_arm:pat2021 ),+ ) => {
2121
| ^ not allowed after `pat2021` fragments

0 commit comments

Comments
 (0)