]> git.lizzy.rs Git - rust.git/blob - src/test/ui/or-patterns/box-patterns.rs
Rollup merge of #83015 - hyd-dev:test-79825-81555, r=Aaron1011
[rust.git] / src / test / ui / or-patterns / box-patterns.rs
1 // Test or-patterns with box-patterns
2
3 // run-pass
4
5 #![feature(box_patterns)]
6
7 #[derive(Debug, PartialEq)]
8 enum MatchArm {
9     Arm(usize),
10     Wild,
11 }
12
13 #[derive(Debug)]
14 enum Test {
15     Foo,
16     Bar,
17     Baz,
18     Qux,
19 }
20
21 fn test(x: Option<Box<Test>>) -> MatchArm {
22     match x {
23         Some(box Test::Foo | box Test::Bar) => MatchArm::Arm(0),
24         Some(box Test::Baz) => MatchArm::Arm(1),
25         Some(_) => MatchArm::Arm(2),
26         _ => MatchArm::Wild,
27     }
28 }
29
30 fn main() {
31     assert_eq!(test(Some(Box::new(Test::Foo))), MatchArm::Arm(0));
32     assert_eq!(test(Some(Box::new(Test::Bar))), MatchArm::Arm(0));
33     assert_eq!(test(Some(Box::new(Test::Baz))), MatchArm::Arm(1));
34     assert_eq!(test(Some(Box::new(Test::Qux))), MatchArm::Arm(2));
35     assert_eq!(test(None), MatchArm::Wild);
36 }