]> git.lizzy.rs Git - rust.git/blob - tests/ui/array-slice-vec/destructure-array-1.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / array-slice-vec / destructure-array-1.rs
1 // run-pass
2
3 // Ensure that we can do a destructuring bind of a fixed-size array,
4 // even when the element type has a destructor.
5
6 struct D { x: u8 }
7
8 impl Drop for D { fn drop(&mut self) { } }
9
10 fn main() {
11     fn d(x: u8) -> D { D { x: x } }
12
13     let d1 = foo([d(1), d(2), d(3), d(4)], 1);
14     let d3 = foo([d(5), d(6), d(7), d(8)], 3);
15     assert_eq!(d1.x, 2);
16     assert_eq!(d3.x, 8);
17 }
18
19 fn foo([a, b, c, d]: [D; 4], i: usize) -> D {
20     match i {
21         0 => a,
22         1 => b,
23         2 => c,
24         3 => d,
25         _ => panic!("unmatched"),
26     }
27 }