rust/tests/ui/macros/macro-pat2021-pattern-followed-by-or.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

23 lines
877 B
Rust
Raw Normal View History

2021-04-27 21:15:59 -05:00
// edition:2021
2021-04-14 05:51:54 -05:00
#![allow(unused_macros)]
2021-04-27 21:15:59 -05:00
macro_rules! foo { ($x:pat | $y:pat) => {} } //~ ERROR `$x:pat` is followed by `|`, which is not allowed for `pat` fragments
2021-04-15 14:27:29 -05:00
macro_rules! baz { ($x:pat_param | $y:pat_param) => {} } // should be ok
2021-04-27 21:15:59 -05:00
macro_rules! qux { ($x:pat_param | $y:pat) => {} } // should be ok
macro_rules! ogg { ($x:pat | $y:pat_param) => {} } //~ ERROR `$x:pat` is followed by `|`, which is not allowed for `pat` fragments
2021-04-14 05:51:54 -05:00
macro_rules! match_any {
2021-04-27 21:15:59 -05:00
( $expr:expr , $( $( $pat:pat)|+ => $expr_arm:pat),+ ) => { //~ ERROR `$pat:pat` may be followed by `|`, which is not allowed for `pat` fragments
2021-04-14 05:51:54 -05:00
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);
}