-
Notifications
You must be signed in to change notification settings - Fork 13.2k
/
Copy pathborrowck-move-and-move.rs
47 lines (37 loc) · 1.23 KB
/
borrowck-move-and-move.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Test that moving on both sides of an `@` pattern is not allowed.
#![feature(bindings_after_at)]
#![feature(slice_patterns)]
fn main() {
struct U; // Not copy!
// Prevent promotion:
fn u() -> U { U }
let a @ b = U;
//~^ ERROR cannot bind by-move with sub-bindings
//~| ERROR use of moved value
let a @ (b, c) = (U, U);
//~^ ERROR cannot bind by-move with sub-bindings
//~| ERROR use of moved value
let a @ (b, c) = (u(), u());
//~^ ERROR cannot bind by-move with sub-bindings
//~| ERROR use of moved value
match Ok(U) {
a @ Ok(b) | a @ Err(b) => {}
//~^ ERROR cannot bind by-move with sub-bindings
//~| ERROR use of moved value
//~| ERROR cannot bind by-move with sub-bindings
//~| ERROR use of moved value
}
fn fun(a @ b: U) {}
//~^ ERROR cannot bind by-move with sub-bindings
//~| ERROR use of moved value
match [u(), u(), u(), u()] {
xs @ [a, .., b] => {}
//~^ ERROR cannot bind by-move with sub-bindings
//~| ERROR use of moved value
}
match [u(), u(), u(), u()] {
xs @ [_, ys @ .., _] => {}
//~^ ERROR cannot bind by-move with sub-bindings
//~| ERROR use of moved value
}
}