]>
Commit | Line | Data |
---|---|---|
85aaf69f SL |
1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | // Ensure that we can do a destructuring bind of a fixed-size array, | |
12 | // even when the element type has a destructor. | |
13 | ||
c34b1796 AL |
14 | |
15 | #![feature(slice_patterns)] | |
16 | ||
85aaf69f SL |
17 | struct D { x: u8 } |
18 | ||
19 | impl Drop for D { fn drop(&mut self) { } } | |
20 | ||
21 | fn main() { | |
22 | fn d(x: u8) -> D { D { x: x } } | |
23 | ||
24 | let d1 = foo([d(1), d(2), d(3), d(4)], 1); | |
25 | let d3 = foo([d(5), d(6), d(7), d(8)], 3); | |
26 | assert_eq!(d1.x, 2); | |
27 | assert_eq!(d3.x, 8); | |
28 | } | |
29 | ||
30 | fn foo([a, b, c, d]: [D; 4], i: usize) -> D { | |
31 | match i { | |
32 | 0 => a, | |
33 | 1 => b, | |
34 | 2 => c, | |
35 | 3 => d, | |
36 | _ => panic!("unmatched"), | |
37 | } | |
38 | } |