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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
// Test that `ref mut? @ pat_with_by_move_bindings` is prevented.
fn main() {
struct U;
// Prevent promotion.
fn u() -> U {
U
}
fn f1(ref a @ b: U) {}
//~^ ERROR cannot move out of value because it is borrowed
//~| ERROR borrow of moved value
fn f2(ref a @ (ref b @ mut c, ref d @ e): (U, U)) {}
//~^ ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
//~| ERROR borrow of moved value
//~| ERROR borrow of moved value
fn f3(ref mut a @ [b, mut c]: [U; 2]) {}
//~^ ERROR cannot move out of value because it is borrowed
//~| ERROR borrow of partially moved value
let ref a @ b = U;
//~^ ERROR cannot move out of value because it is borrowed
let ref a @ (ref b @ mut c, ref d @ e) = (U, U);
//~^ ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
let ref mut a @ [b, mut c] = [U, U];
//~^ ERROR cannot move out of value because it is borrowed
//~| ERROR borrow of partially moved value
let ref a @ b = u();
//~^ ERROR cannot move out of value because it is borrowed
//~| ERROR borrow of moved value
let ref a @ (ref b @ mut c, ref d @ e) = (u(), u());
//~^ ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
//~| ERROR borrow of moved value
//~| ERROR borrow of moved value
let ref mut a @ [b, mut c] = [u(), u()];
//~^ ERROR cannot move out of value because it is borrowed
//~| ERROR borrow of partially moved value
match Some(U) {
ref a @ Some(b) => {}
//~^ ERROR cannot move out of value because it is borrowed
None => {}
}
match Some((U, U)) {
ref a @ Some((ref b @ mut c, ref d @ e)) => {}
//~^ ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
None => {}
}
match Some([U, U]) {
ref mut a @ Some([b, mut c]) => {}
//~^ ERROR cannot move out of value because it is borrowed
None => {}
}
match Some(u()) {
ref a @ Some(b) => {}
//~^ ERROR cannot move out of value because it is borrowed
None => {}
}
match Some((u(), u())) {
ref a @ Some((ref b @ mut c, ref d @ e)) => {}
//~^ ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
//~| ERROR borrow of moved value
//~| ERROR borrow of moved value
None => {}
}
match Some([u(), u()]) {
ref mut a @ Some([b, mut c]) => {}
//~^ ERROR cannot move out of value because it is borrowed
None => {}
}
}
|