]> git.proxmox.com Git - rustc.git/blob - src/test/ui/pattern/bindings-after-at/box-patterns.rs
New upstream version 1.57.0+dfsg1
[rustc.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(box_patterns)]
6
7 #[derive(Debug, PartialEq)]
8 enum MatchArm {
9 Arm(usize),
10 Wild,
11 }
12
13 fn test(x: Option<Box<i32>>) -> MatchArm {
14 match x {
15 ref bar @ Some(box n) if n > 0 => {
16 // bar is a &Option<Box<i32>>
17 assert_eq!(bar, &x);
18
19 MatchArm::Arm(0)
20 },
21 Some(ref bar @ box n) if n < 0 => {
22 // bar is a &Box<i32> here
23 assert_eq!(**bar, n);
24
25 MatchArm::Arm(1)
26 },
27 _ => MatchArm::Wild,
28 }
29 }
30
31 fn main() {
32 assert_eq!(test(Some(Box::new(2))), MatchArm::Arm(0));
33 assert_eq!(test(Some(Box::new(-1))), MatchArm::Arm(1));
34 assert_eq!(test(Some(Box::new(0))), MatchArm::Wild);
35 }