]> git.lizzy.rs Git - rust.git/blob - src/test/ui/or-patterns/macro-pat.rs
Rollup merge of #80269 - pickfire:patch-4, r=joshtriplett
[rust.git] / src / test / ui / or-patterns / macro-pat.rs
1 // run-pass
2 // edition:2021
3
4 use Foo::*;
5
6 #[allow(dead_code)]
7 #[derive(Eq, PartialEq, Debug)]
8 enum Foo {
9     A(u64),
10     B(u64),
11     C,
12     D,
13 }
14
15 macro_rules! foo {
16     ($orpat:pat, $val:expr) => {
17         match $val {
18             x @ ($orpat) => x, // leading vert would not be allowed in $orpat
19             _ => B(0xDEADBEEFu64),
20         }
21     };
22 }
23
24 macro_rules! bar {
25     ($orpat:pat, $val:expr) => {
26         match $val {
27             $orpat => 42, // leading vert allowed here
28             _ => 0xDEADBEEFu64,
29         }
30     };
31 }
32
33 fn main() {
34     // Test or-pattern.
35     let y = foo!(A(_)|B(_), A(32));
36     assert_eq!(y, A(32));
37
38     // Leading vert in or-pattern.
39     let y = bar!(|C| D, C);
40     assert_eq!(y, 42u64);
41 }