summary refs log tree commit diff
path: root/src/test/ui/pattern/bindings-after-at/box-patterns.rs
blob: ef9669a6b9e5ae9fca05f23ff0dea1f983269711 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Test bindings-after-at with box-patterns

// run-pass

#![feature(bindings_after_at)]
#![feature(box_patterns)]

#[derive(Debug, PartialEq)]
enum MatchArm {
    Arm(usize),
    Wild,
}

fn test(x: Option<Box<i32>>) -> MatchArm {
    match x {
        ref bar @ Some(box n) if n > 0 => {
            // bar is a &Option<Box<i32>>
            assert_eq!(bar, &x);

            MatchArm::Arm(0)
        },
        Some(ref bar @ box n) if n < 0 => {
            // bar is a &Box<i32> here
            assert_eq!(**bar, n);

            MatchArm::Arm(1)
        },
        _ => MatchArm::Wild,
    }
}

fn main() {
    assert_eq!(test(Some(Box::new(2))), MatchArm::Arm(0));
    assert_eq!(test(Some(Box::new(-1))), MatchArm::Arm(1));
    assert_eq!(test(Some(Box::new(0))), MatchArm::Wild);
}