]> git.lizzy.rs Git - rust.git/blob - src/test/ui/or-patterns/struct-like.rs
Rollup merge of #80269 - pickfire:patch-4, r=joshtriplett
[rust.git] / src / test / ui / or-patterns / struct-like.rs
1 // run-pass
2
3 #[derive(Debug)]
4 enum Other {
5     One,
6     Two,
7     Three,
8 }
9
10 #[derive(Debug)]
11 enum Test {
12     Foo { first: usize, second: usize },
13     Bar { other: Option<Other> },
14     Baz,
15 }
16
17 fn test(x: Option<Test>) -> bool {
18     match x {
19         Some(
20             Test::Foo { first: 1024 | 2048, second: 2048 | 4096 }
21             | Test::Bar { other: Some(Other::One | Other::Two) },
22         ) => true,
23         // wild case
24         Some(_) => false,
25         // empty case
26         None => false,
27     }
28 }
29
30 fn main() {
31     assert!(test(Some(Test::Foo { first: 1024, second: 4096 })));
32     assert!(!test(Some(Test::Foo { first: 2048, second: 8192 })));
33     assert!(!test(Some(Test::Foo { first: 42, second: 2048 })));
34     assert!(test(Some(Test::Bar { other: Some(Other::One) })));
35     assert!(test(Some(Test::Bar { other: Some(Other::Two) })));
36     assert!(!test(Some(Test::Bar { other: Some(Other::Three) })));
37     assert!(!test(Some(Test::Bar { other: None })));
38     assert!(!test(Some(Test::Baz)));
39     assert!(!test(None));
40 }