move_ref_patterns: introduce tests
bindings_after_at: harden tests
This commit is contained in:
parent
7af9ff3e69
commit
d984f127f6
50 changed files with 1931 additions and 553 deletions
|
@ -0,0 +1,50 @@
|
|||
#![feature(move_ref_pattern)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
struct U;
|
||||
|
||||
fn slice() {
|
||||
let mut arr = [U, U, U, U, U];
|
||||
let hold_all = &arr;
|
||||
let [ref _x0_hold, _x1, ref xs_hold @ ..] = arr; //~ ERROR cannot move out of `arr[..]`
|
||||
_x1 = U; //~ ERROR cannot assign twice to immutable variable `_x1`
|
||||
drop(hold_all);
|
||||
let [_x0, ..] = arr; //~ ERROR cannot move out of `arr[..]`
|
||||
drop(_x0_hold);
|
||||
let [_, _, ref mut _x2, _x3, mut _x4] = arr;
|
||||
//~^ ERROR cannot borrow `arr[..]` as mutable
|
||||
//~| ERROR cannot move out of `arr[..]` because it is borrowed
|
||||
//~| ERROR cannot move out of `arr[..]` because it is borrowed
|
||||
drop(xs_hold);
|
||||
}
|
||||
|
||||
fn tuple() {
|
||||
let mut tup = (U, U, U, U);
|
||||
let (ref _x0, _x1, ref _x2, ..) = tup;
|
||||
_x1 = U; //~ ERROR cannot assign twice to immutable variable
|
||||
let _x0_hold = &mut tup.0; //~ ERROR cannot borrow `tup.0` as mutable because it is also
|
||||
let (ref mut _x0_hold, ..) = tup; //~ ERROR cannot borrow `tup.0` as mutable because it is also
|
||||
*_x0 = U; //~ ERROR cannot assign to `*_x0` which is behind a `&` reference
|
||||
*_x2 = U; //~ ERROR cannot assign to `*_x2` which is behind a `&` reference
|
||||
drop(tup.1); //~ ERROR use of moved value: `tup.1`
|
||||
let _x1_hold = &tup.1; //~ ERROR borrow of moved value: `tup.1`
|
||||
let (.., ref mut _x3) = tup;
|
||||
let _x3_hold = &tup.3; //~ ERROR cannot borrow `tup.3` as immutable
|
||||
let _x3_hold = &mut tup.3; //~ ERROR cannot borrow `tup.3` as mutable more
|
||||
let (.., ref mut _x4_hold) = tup; //~ ERROR cannot borrow `tup.3` as mutable more
|
||||
let (.., ref _x4_hold) = tup; //~ ERROR cannot borrow `tup.3` as immutable
|
||||
drop(_x3);
|
||||
}
|
||||
|
||||
fn closure() {
|
||||
let mut tup = (U, U, U);
|
||||
let c1 = || {
|
||||
let (ref _x0, _x1, _) = tup;
|
||||
};
|
||||
let c2 = || {
|
||||
//~^ ERROR use of moved value
|
||||
let (ref mut _x0, _, _x2) = tup;
|
||||
};
|
||||
drop(c1);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue