summaryrefslogtreecommitdiffstats
path: root/tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.rs
blob: a6144c9497d0483255c3fbaa23c314d36ab49292 (plain)
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
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);
}