]> git.lizzy.rs Git - rust.git/blob - src/test/ui/pattern/bindings-after-at/box-patterns.rs
Rollup merge of #70038 - DutchGhost:const-forget-tests, r=RalfJung
[rust.git] / src / test / ui / pattern / bindings-after-at / box-patterns.rs
1 // Test bindings-after-at with box-patterns
2
3 // run-pass
4
5 #![feature(bindings_after_at)]
6 #![feature(box_patterns)]
7
8 #[derive(Debug, PartialEq)]
9 enum MatchArm {
10     Arm(usize),
11     Wild,
12 }
13
14 fn test(x: Option<Box<i32>>) -> MatchArm {
15     match x {
16         ref bar @ Some(box n) if n > 0 => {
17             // bar is a &Option<Box<i32>>
18             assert_eq!(bar, &x);
19
20             MatchArm::Arm(0)
21         },
22         Some(ref bar @ box n) if n < 0 => {
23             // bar is a &Box<i32> here
24             assert_eq!(**bar, n);
25
26             MatchArm::Arm(1)
27         },
28         _ => MatchArm::Wild,
29     }
30 }
31
32 fn main() {
33     assert_eq!(test(Some(Box::new(2))), MatchArm::Arm(0));
34     assert_eq!(test(Some(Box::new(-1))), MatchArm::Arm(1));
35     assert_eq!(test(Some(Box::new(0))), MatchArm::Wild);
36 }