]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-move-out-from-array-use-match.rs
Rollup merge of #106644 - alexcrichton:update-wasi-toolchain, r=cuviper
[rust.git] / tests / ui / borrowck / borrowck-move-out-from-array-use-match.rs
1 fn array() -> [(String, String); 3] {
2     Default::default()
3 }
4
5 // Const Index + Const Index
6
7 fn move_out_from_begin_and_end() {
8     let a = array();
9     match a {
10         [_, _, _x] => {}
11     }
12     match a {
13         [.., ref _y] => {} //~ ERROR [E0382]
14     }
15 }
16
17 fn move_out_from_begin_field_and_end() {
18     let a = array();
19     match a {
20         [_, _, (_x, _)] => {}
21     }
22     match a {
23         [.., ref _y] => {} //~ ERROR [E0382]
24     }
25 }
26
27 fn move_out_from_begin_field_and_end_field() {
28     let a = array();
29     match a {
30         [_, _, (_x, _)] => {}
31     }
32     match a {
33         [.., (ref _y, _)] => {} //~ ERROR [E0382]
34     }
35 }
36
37 // Const Index + Slice
38
39 fn move_out_by_const_index_and_subslice() {
40     let a = array();
41     match a {
42         [_x, _, _] => {}
43     }
44     match a {
45         //~^ ERROR [E0382]
46         [ref _y @ .., _, _] => {}
47     }
48 }
49
50 fn move_out_by_const_index_end_and_subslice() {
51     let a = array();
52     match a {
53         [.., _x] => {}
54     }
55     match a {
56         //~^ ERROR [E0382]
57         [_, _, ref _y @ ..] => {}
58     }
59 }
60
61 fn move_out_by_const_index_field_and_subslice() {
62     let a = array();
63     match a {
64         [(_x, _), _, _] => {}
65     }
66     match a {
67         //~^ ERROR [E0382]
68         [ref _y @ .., _, _] => {}
69     }
70 }
71
72 fn move_out_by_const_index_end_field_and_subslice() {
73     let a = array();
74     match a {
75         [.., (_x, _)] => {}
76     }
77     match a {
78         //~^ ERROR [E0382]
79         [_, _, ref _y @ ..] => {}
80     }
81 }
82
83 fn move_out_by_subslice_and_const_index_field() {
84     let a = array();
85     match a {
86         [_y @ .., _, _] => {}
87     }
88     match a {
89         [(ref _x, _), _, _] => {} //~ ERROR [E0382]
90     }
91 }
92
93 fn move_out_by_subslice_and_const_index_end_field() {
94     let a = array();
95     match a {
96         [_, _, _y @ ..] => {}
97     }
98     match a {
99         [.., (ref _x, _)] => {} //~ ERROR [E0382]
100     }
101 }
102
103 // Slice + Slice
104
105 fn move_out_by_subslice_and_subslice() {
106     let a = array();
107     match a {
108         [x @ .., _] => {}
109     }
110     match a {
111         //~^ ERROR [E0382]
112         [_, ref _y @ ..] => {}
113     }
114 }
115
116 // Move + Assign
117
118 fn move_out_and_assign_end() {
119     let mut a = array();
120     match a {
121         [_, _, _x] => {}
122     }
123     a[2] = Default::default(); //~ ERROR [E0382]
124 }
125
126 fn move_out_and_assign_end_field() {
127     let mut a = array();
128     match a {
129         [_, _, (_x, _)] => {}
130     }
131     a[2].1 = Default::default(); //~ ERROR [E0382]
132 }
133
134 fn move_out_slice_and_assign_end() {
135     let mut a = array();
136     match a {
137         [_, _, _x @ ..] => {}
138     }
139     a[0] = Default::default(); //~ ERROR [E0382]
140 }
141
142 fn move_out_slice_and_assign_end_field() {
143     let mut a = array();
144     match a {
145         [_, _, _x @ ..] => {}
146     }
147     a[0].1 = Default::default(); //~ ERROR [E0382]
148 }
149
150 fn main() {}