]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/destructure-array-1.rs
Imported Upstream version 1.0.0~beta.3
[rustc.git] / src / test / run-pass / destructure-array-1.rs
CommitLineData
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
17struct D { x: u8 }
18
19impl Drop for D { fn drop(&mut self) { } }
20
21fn 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
30fn 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}