add macro-or-patterns-2021 test
This commit is contained in:
parent
132b4e5d16
commit
0e9de930ac
2 changed files with 47 additions and 0 deletions
21
src/test/ui/macros/macro-or-patterns-2021.rs
Normal file
21
src/test/ui/macros/macro-or-patterns-2021.rs
Normal file
|
@ -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);
|
||||||
|
}
|
26
src/test/ui/macros/macro-or-patterns-2021.stderr
Normal file
26
src/test/ui/macros/macro-or-patterns-2021.stderr
Normal file
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue