]>
Commit | Line | Data |
---|---|---|
dfeec247 XL |
1 | // check-pass |
2 | ||
3 | // Test `@` patterns combined with `box` patterns. | |
4 | ||
dfeec247 XL |
5 | #![feature(box_patterns)] |
6 | ||
7 | #[derive(Copy, Clone)] | |
8 | struct C; | |
9 | ||
10 | fn c() -> C { C } | |
11 | ||
12 | struct NC; | |
13 | ||
14 | fn nc() -> NC { NC } | |
15 | ||
16 | fn main() { | |
17 | let ref a @ box b = Box::new(C); // OK; the type is `Copy`. | |
18 | drop(b); | |
19 | drop(b); | |
20 | drop(a); | |
21 | ||
22 | let ref a @ box b = Box::new(c()); // OK; the type is `Copy`. | |
23 | drop(b); | |
24 | drop(b); | |
25 | drop(a); | |
26 | ||
27 | fn f3(ref a @ box b: Box<C>) { // OK; the type is `Copy`. | |
28 | drop(b); | |
29 | drop(b); | |
30 | drop(a); | |
31 | } | |
32 | match Box::new(c()) { | |
33 | ref a @ box b => { // OK; the type is `Copy`. | |
34 | drop(b); | |
35 | drop(b); | |
36 | drop(a); | |
37 | } | |
38 | } | |
39 | ||
40 | let ref a @ box ref b = Box::new(NC); // OK. | |
41 | drop(a); | |
42 | drop(b); | |
43 | ||
44 | fn f4(ref a @ box ref b: Box<NC>) { // OK. | |
45 | drop(a); | |
46 | drop(b) | |
47 | } | |
48 | ||
49 | match Box::new(nc()) { | |
50 | ref a @ box ref b => { // OK. | |
51 | drop(a); | |
52 | drop(b); | |
53 | } | |
54 | } | |
55 | ||
56 | match Box::new([Ok(c()), Err(nc()), Ok(c())]) { | |
57 | box [Ok(a), ref xs @ .., Err(ref b)] => { | |
58 | let _: C = a; | |
59 | let _: &[Result<C, NC>; 1] = xs; | |
60 | let _: &NC = b; | |
61 | } | |
62 | _ => {} | |
63 | } | |
64 | ||
65 | match [Ok(Box::new(c())), Err(Box::new(nc())), Ok(Box::new(c())), Ok(Box::new(c()))] { | |
66 | [Ok(box a), ref xs @ .., Err(box ref b), Err(box ref c)] => { | |
67 | let _: C = a; | |
68 | let _: &[Result<Box<C>, Box<NC>>; 1] = xs; | |
69 | let _: &NC = b; | |
70 | let _: &NC = c; | |
71 | } | |
72 | _ => {} | |
73 | } | |
74b04a01 XL |
74 | |
75 | match Box::new([Ok(c()), Err(nc()), Ok(c())]) { | |
76 | box [Ok(a), ref xs @ .., Err(b)] => {} | |
77 | _ => {} | |
78 | } | |
79 | ||
80 | match [Ok(Box::new(c())), Err(Box::new(nc())), Ok(Box::new(c())), Ok(Box::new(c()))] { | |
81 | [Ok(box ref a), ref xs @ .., Err(box b), Err(box ref mut c)] => {} | |
82 | _ => {} | |
83 | } | |
dfeec247 | 84 | } |