blob: 9db37253c5368f862d56853178d697c99fb98835 (
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
|
// Test bindings-after-at with box-patterns
// run-pass
#![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);
}
|