]>
Commit | Line | Data |
---|---|---|
b7449926 XL |
1 | #[derive(Clone)] |
2 | enum Either { | |
3 | One(X), | |
4 | Two(X), | |
5 | } | |
6 | ||
7 | #[derive(Clone)] | |
8 | struct X(Y); | |
9 | ||
10 | #[derive(Clone)] | |
11 | struct Y; | |
12 | ||
13 | pub fn main() { | |
14 | let e = Either::One(X(Y)); | |
15 | let mut em = Either::One(X(Y)); | |
16 | ||
17 | let r = &e; | |
18 | let rm = &mut Either::One(X(Y)); | |
19 | ||
20 | let x = X(Y); | |
21 | let mut xm = X(Y); | |
22 | ||
23 | let s = &x; | |
24 | let sm = &mut X(Y); | |
25 | ||
26 | let ve = vec![Either::One(X(Y))]; | |
27 | ||
28 | let vr = &ve; | |
29 | let vrm = &mut vec![Either::One(X(Y))]; | |
30 | ||
31 | let vx = vec![X(Y)]; | |
32 | ||
33 | let vs = &vx; | |
34 | let vsm = &mut vec![X(Y)]; | |
35 | ||
e1599b0c | 36 | // move from Either/X place |
b7449926 XL |
37 | |
38 | let X(_t) = *s; | |
39 | //~^ ERROR cannot move | |
dc9dc135 | 40 | //~| HELP consider borrowing here |
b7449926 XL |
41 | //~| SUGGESTION s |
42 | if let Either::One(_t) = *r { } | |
43 | //~^ ERROR cannot move | |
dc9dc135 | 44 | //~| HELP consider borrowing here |
b7449926 XL |
45 | //~| SUGGESTION r |
46 | while let Either::One(_t) = *r { } | |
47 | //~^ ERROR cannot move | |
dc9dc135 | 48 | //~| HELP consider borrowing here |
b7449926 XL |
49 | //~| SUGGESTION r |
50 | match *r { | |
51 | //~^ ERROR cannot move | |
dc9dc135 | 52 | //~| HELP consider borrowing here |
b7449926 XL |
53 | //~| SUGGESTION r |
54 | Either::One(_t) | |
55 | | Either::Two(_t) => (), | |
56 | } | |
57 | match *r { | |
58 | //~^ ERROR cannot move | |
dc9dc135 | 59 | //~| HELP consider borrowing here |
b7449926 XL |
60 | //~| SUGGESTION r |
61 | Either::One(_t) => (), | |
62 | Either::Two(ref _t) => (), | |
63 | // FIXME: should suggest removing `ref` too | |
64 | } | |
65 | ||
66 | let X(_t) = *sm; | |
67 | //~^ ERROR cannot move | |
dc9dc135 | 68 | //~| HELP consider borrowing here |
b7449926 XL |
69 | //~| SUGGESTION sm |
70 | if let Either::One(_t) = *rm { } | |
71 | //~^ ERROR cannot move | |
dc9dc135 | 72 | //~| HELP consider borrowing here |
b7449926 XL |
73 | //~| SUGGESTION rm |
74 | while let Either::One(_t) = *rm { } | |
75 | //~^ ERROR cannot move | |
dc9dc135 | 76 | //~| HELP consider borrowing here |
b7449926 XL |
77 | //~| SUGGESTION rm |
78 | match *rm { | |
79 | //~^ ERROR cannot move | |
dc9dc135 | 80 | //~| HELP consider borrowing here |
b7449926 XL |
81 | //~| SUGGESTION rm |
82 | Either::One(_t) | |
83 | | Either::Two(_t) => (), | |
84 | } | |
85 | match *rm { | |
86 | //~^ ERROR cannot move | |
dc9dc135 | 87 | //~| HELP consider borrowing here |
b7449926 XL |
88 | //~| SUGGESTION rm |
89 | Either::One(_t) => (), | |
90 | Either::Two(ref _t) => (), | |
91 | // FIXME: should suggest removing `ref` too | |
92 | } | |
93 | match *rm { | |
94 | //~^ ERROR cannot move | |
dc9dc135 | 95 | //~| HELP consider borrowing here |
b7449926 XL |
96 | //~| SUGGESTION rm |
97 | Either::One(_t) => (), | |
98 | Either::Two(ref mut _t) => (), | |
99 | // FIXME: should suggest removing `ref` too | |
100 | } | |
101 | ||
102 | let X(_t) = vs[0]; | |
103 | //~^ ERROR cannot move | |
104 | //~| HELP consider borrowing here | |
105 | //~| SUGGESTION &vs[0] | |
106 | if let Either::One(_t) = vr[0] { } | |
107 | //~^ ERROR cannot move | |
108 | //~| HELP consider borrowing here | |
109 | //~| SUGGESTION &vr[0] | |
110 | while let Either::One(_t) = vr[0] { } | |
111 | //~^ ERROR cannot move | |
112 | //~| HELP consider borrowing here | |
113 | //~| SUGGESTION &vr[0] | |
114 | match vr[0] { | |
115 | //~^ ERROR cannot move | |
116 | //~| HELP consider borrowing here | |
117 | //~| SUGGESTION &vr[0] | |
118 | Either::One(_t) | |
119 | | Either::Two(_t) => (), | |
120 | } | |
121 | match vr[0] { | |
122 | //~^ ERROR cannot move | |
123 | //~| HELP consider borrowing here | |
124 | //~| SUGGESTION &vr[0] | |
125 | Either::One(_t) => (), | |
126 | Either::Two(ref _t) => (), | |
127 | // FIXME: should suggest removing `ref` too | |
128 | } | |
129 | ||
130 | let X(_t) = vsm[0]; | |
131 | //~^ ERROR cannot move | |
132 | //~| HELP consider borrowing here | |
133 | //~| SUGGESTION &vsm[0] | |
134 | if let Either::One(_t) = vrm[0] { } | |
135 | //~^ ERROR cannot move | |
136 | //~| HELP consider borrowing here | |
137 | //~| SUGGESTION &vrm[0] | |
138 | while let Either::One(_t) = vrm[0] { } | |
139 | //~^ ERROR cannot move | |
140 | //~| HELP consider borrowing here | |
141 | //~| SUGGESTION &vrm[0] | |
142 | match vrm[0] { | |
143 | //~^ ERROR cannot move | |
144 | //~| HELP consider borrowing here | |
145 | //~| SUGGESTION &vrm[0] | |
146 | Either::One(_t) | |
147 | | Either::Two(_t) => (), | |
148 | } | |
149 | match vrm[0] { | |
150 | //~^ ERROR cannot move | |
151 | //~| HELP consider borrowing here | |
152 | //~| SUGGESTION &vrm[0] | |
153 | Either::One(_t) => (), | |
154 | Either::Two(ref _t) => (), | |
155 | // FIXME: should suggest removing `ref` too | |
156 | } | |
157 | match vrm[0] { | |
158 | //~^ ERROR cannot move | |
159 | //~| HELP consider borrowing here | |
160 | //~| SUGGESTION &vrm[0] | |
161 | Either::One(_t) => (), | |
162 | Either::Two(ref mut _t) => (), | |
163 | // FIXME: should suggest removing `ref` too | |
164 | } | |
165 | ||
e1599b0c | 166 | // move from &Either/&X place |
b7449926 XL |
167 | |
168 | let &X(_t) = s; | |
169 | //~^ ERROR cannot move | |
170 | //~| HELP consider removing the `&` | |
171 | //~| SUGGESTION X(_t) | |
172 | if let &Either::One(_t) = r { } | |
173 | //~^ ERROR cannot move | |
174 | //~| HELP consider removing the `&` | |
175 | //~| SUGGESTION Either::One(_t) | |
176 | while let &Either::One(_t) = r { } | |
177 | //~^ ERROR cannot move | |
178 | //~| HELP consider removing the `&` | |
179 | //~| SUGGESTION Either::One(_t) | |
180 | match r { | |
181 | //~^ ERROR cannot move | |
182 | &Either::One(_t) | |
183 | //~^ HELP consider removing the `&` | |
184 | //~| SUGGESTION Either::One(_t) | |
185 | | &Either::Two(_t) => (), | |
186 | // FIXME: would really like a suggestion here too | |
187 | } | |
188 | match r { | |
189 | //~^ ERROR cannot move | |
190 | &Either::One(_t) => (), | |
191 | //~^ HELP consider removing the `&` | |
192 | //~| SUGGESTION Either::One(_t) | |
193 | &Either::Two(ref _t) => (), | |
194 | } | |
195 | match r { | |
196 | //~^ ERROR cannot move | |
197 | &Either::One(_t) => (), | |
198 | //~^ HELP consider removing the `&` | |
199 | //~| SUGGESTION Either::One(_t) | |
200 | Either::Two(_t) => (), | |
201 | } | |
202 | fn f1(&X(_t): &X) { } | |
203 | //~^ ERROR cannot move | |
204 | //~| HELP consider removing the `&` | |
205 | //~| SUGGESTION X(_t) | |
206 | ||
207 | let &mut X(_t) = sm; | |
208 | //~^ ERROR cannot move | |
209 | //~| HELP consider removing the `&mut` | |
210 | //~| SUGGESTION X(_t) | |
211 | if let &mut Either::One(_t) = rm { } | |
212 | //~^ ERROR cannot move | |
213 | //~| HELP consider removing the `&mut` | |
214 | //~| SUGGESTION Either::One(_t) | |
215 | while let &mut Either::One(_t) = rm { } | |
216 | //~^ ERROR cannot move | |
217 | //~| HELP consider removing the `&mut` | |
218 | //~| SUGGESTION Either::One(_t) | |
219 | match rm { | |
220 | //~^ ERROR cannot move | |
221 | &mut Either::One(_t) => (), | |
222 | //~^ HELP consider removing the `&mut` | |
223 | //~| SUGGESTION Either::One(_t) | |
224 | &mut Either::Two(_t) => (), | |
225 | //~^ HELP consider removing the `&mut` | |
226 | //~| SUGGESTION Either::Two(_t) | |
227 | } | |
228 | match rm { | |
229 | //~^ ERROR cannot move | |
230 | &mut Either::One(_t) => (), | |
231 | //~^ HELP consider removing the `&mut` | |
232 | //~| SUGGESTION Either::One(_t) | |
233 | &mut Either::Two(ref _t) => (), | |
234 | } | |
235 | match rm { | |
236 | //~^ ERROR cannot move | |
237 | &mut Either::One(_t) => (), | |
238 | //~^ HELP consider removing the `&mut` | |
239 | //~| SUGGESTION Either::One(_t) | |
240 | &mut Either::Two(ref mut _t) => (), | |
241 | } | |
242 | match rm { | |
243 | //~^ ERROR cannot move | |
244 | &mut Either::One(_t) => (), | |
245 | //~^ HELP consider removing the `&mut` | |
246 | //~| SUGGESTION Either::One(_t) | |
247 | Either::Two(_t) => (), | |
248 | } | |
249 | fn f2(&mut X(_t): &mut X) { } | |
250 | //~^ ERROR cannot move | |
251 | //~| HELP consider removing the `&mut` | |
252 | //~| SUGGESTION X(_t) | |
253 | ||
e1599b0c | 254 | // move from tuple of &Either/&X |
b7449926 XL |
255 | |
256 | // FIXME: These should have suggestions. | |
257 | ||
258 | let (&X(_t),) = (&x.clone(),); | |
259 | //~^ ERROR cannot move | |
260 | if let (&Either::One(_t),) = (&e.clone(),) { } | |
261 | //~^ ERROR cannot move | |
262 | while let (&Either::One(_t),) = (&e.clone(),) { } | |
263 | //~^ ERROR cannot move | |
264 | match (&e.clone(),) { | |
265 | //~^ ERROR cannot move | |
266 | (&Either::One(_t),) | |
267 | | (&Either::Two(_t),) => (), | |
268 | } | |
269 | fn f3((&X(_t),): (&X,)) { } | |
270 | //~^ ERROR cannot move | |
271 | ||
272 | let (&mut X(_t),) = (&mut xm.clone(),); | |
273 | //~^ ERROR cannot move | |
274 | if let (&mut Either::One(_t),) = (&mut em.clone(),) { } | |
275 | //~^ ERROR cannot move | |
276 | while let (&mut Either::One(_t),) = (&mut em.clone(),) { } | |
277 | //~^ ERROR cannot move | |
278 | match (&mut em.clone(),) { | |
279 | //~^ ERROR cannot move | |
280 | (&mut Either::One(_t),) => (), | |
281 | (&mut Either::Two(_t),) => (), | |
282 | } | |
283 | fn f4((&mut X(_t),): (&mut X,)) { } | |
284 | //~^ ERROR cannot move | |
285 | ||
e1599b0c | 286 | // move from &Either/&X value |
b7449926 XL |
287 | |
288 | let &X(_t) = &x; | |
289 | //~^ ERROR cannot move | |
290 | //~| HELP consider removing the `&` | |
291 | //~| SUGGESTION X(_t) | |
292 | if let &Either::One(_t) = &e { } | |
293 | //~^ ERROR cannot move | |
294 | //~| HELP consider removing the `&` | |
295 | //~| SUGGESTION Either::One(_t) | |
296 | while let &Either::One(_t) = &e { } | |
297 | //~^ ERROR cannot move | |
298 | //~| HELP consider removing the `&` | |
299 | //~| SUGGESTION Either::One(_t) | |
300 | match &e { | |
301 | //~^ ERROR cannot move | |
302 | &Either::One(_t) | |
303 | //~^ HELP consider removing the `&` | |
304 | //~| SUGGESTION Either::One(_t) | |
305 | | &Either::Two(_t) => (), | |
306 | // FIXME: would really like a suggestion here too | |
307 | } | |
308 | match &e { | |
309 | //~^ ERROR cannot move | |
310 | &Either::One(_t) => (), | |
311 | //~^ HELP consider removing the `&` | |
312 | //~| SUGGESTION Either::One(_t) | |
313 | &Either::Two(ref _t) => (), | |
314 | } | |
315 | match &e { | |
316 | //~^ ERROR cannot move | |
317 | &Either::One(_t) => (), | |
318 | //~^ HELP consider removing the `&` | |
319 | //~| SUGGESTION Either::One(_t) | |
320 | Either::Two(_t) => (), | |
321 | } | |
322 | ||
323 | let &mut X(_t) = &mut xm; | |
324 | //~^ ERROR cannot move | |
325 | //~| HELP consider removing the `&mut` | |
326 | //~| SUGGESTION X(_t) | |
327 | if let &mut Either::One(_t) = &mut em { } | |
328 | //~^ ERROR cannot move | |
329 | //~| HELP consider removing the `&mut` | |
330 | //~| SUGGESTION Either::One(_t) | |
331 | while let &mut Either::One(_t) = &mut em { } | |
332 | //~^ ERROR cannot move | |
333 | //~| HELP consider removing the `&mut` | |
334 | //~| SUGGESTION Either::One(_t) | |
335 | match &mut em { | |
336 | //~^ ERROR cannot move | |
337 | &mut Either::One(_t) | |
338 | //~^ HELP consider removing the `&mut` | |
339 | //~| SUGGESTION Either::One(_t) | |
340 | | &mut Either::Two(_t) => (), | |
341 | // FIXME: would really like a suggestion here too | |
342 | } | |
343 | match &mut em { | |
344 | //~^ ERROR cannot move | |
345 | &mut Either::One(_t) => (), | |
346 | //~^ HELP consider removing the `&mut` | |
347 | //~| SUGGESTION Either::One(_t) | |
348 | &mut Either::Two(ref _t) => (), | |
349 | } | |
350 | match &mut em { | |
351 | //~^ ERROR cannot move | |
352 | &mut Either::One(_t) => (), | |
353 | //~^ HELP consider removing the `&mut` | |
354 | //~| SUGGESTION Either::One(_t) | |
355 | &mut Either::Two(ref mut _t) => (), | |
356 | } | |
357 | match &mut em { | |
358 | //~^ ERROR cannot move | |
359 | &mut Either::One(_t) => (), | |
360 | //~^ HELP consider removing the `&mut` | |
361 | //~| SUGGESTION Either::One(_t) | |
362 | Either::Two(_t) => (), | |
363 | } | |
364 | } |