]> git.lizzy.rs Git - rust.git/blob - src/test/ui/moves/move-out-of-array-ref.rs
slice_patterns: remove gates in tests
[rust.git] / src / test / ui / moves / move-out-of-array-ref.rs
1 // Ensure that we cannot move out of a reference to a fixed-size array
2
3 struct D { _x: u8 }
4
5 impl Drop for D { fn drop(&mut self) { } }
6
7 fn move_elem(a: &[D; 4]) -> D {
8     let [_, e, _, _] = *a;              //~ ERROR cannot move
9     e
10 }
11
12 fn move_subarr(a: &[D; 4]) -> [D; 2] {
13     let [_, s @ .. , _] = *a;           //~ ERROR cannot move
14     s
15 }
16
17 fn move_elem_mut(a: &mut [D; 4]) -> D {
18     let [_, e, _, _] = *a;              //~ ERROR cannot move
19     e
20 }
21
22 fn move_subarr_mut(a: &mut [D; 4]) -> [D; 2] {
23     let [_, s @ .. , _] = *a;           //~ ERROR cannot move
24     s
25 }
26
27 fn main() {
28     fn d() -> D { D { _x: 0 } }
29
30     move_elem(&[d(), d(), d(), d()]);
31     move_subarr(&[d(), d(), d(), d()]);
32     move_elem_mut(&mut [d(), d(), d(), d()]);
33     move_subarr_mut(&mut [d(), d(), d(), d()]);
34 }