summaryrefslogtreecommitdiffstats
path: root/tests/ui/borrowck/borrowck-move-out-from-array-use-match.rs
blob: 604a25cdcc1d689ecebacc42584aacd06ca4a69d (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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
fn array() -> [(String, String); 3] {
    Default::default()
}

// Const Index + Const Index

fn move_out_from_begin_and_end() {
    let a = array();
    match a {
        [_, _, _x] => {}
    }
    match a {
        [.., ref _y] => {} //~ ERROR [E0382]
    }
}

fn move_out_from_begin_field_and_end() {
    let a = array();
    match a {
        [_, _, (_x, _)] => {}
    }
    match a {
        [.., ref _y] => {} //~ ERROR [E0382]
    }
}

fn move_out_from_begin_field_and_end_field() {
    let a = array();
    match a {
        [_, _, (_x, _)] => {}
    }
    match a {
        [.., (ref _y, _)] => {} //~ ERROR [E0382]
    }
}

// Const Index + Slice

fn move_out_by_const_index_and_subslice() {
    let a = array();
    match a {
        [_x, _, _] => {}
    }
    match a {
        //~^ ERROR [E0382]
        [ref _y @ .., _, _] => {}
    }
}

fn move_out_by_const_index_end_and_subslice() {
    let a = array();
    match a {
        [.., _x] => {}
    }
    match a {
        //~^ ERROR [E0382]
        [_, _, ref _y @ ..] => {}
    }
}

fn move_out_by_const_index_field_and_subslice() {
    let a = array();
    match a {
        [(_x, _), _, _] => {}
    }
    match a {
        //~^ ERROR [E0382]
        [ref _y @ .., _, _] => {}
    }
}

fn move_out_by_const_index_end_field_and_subslice() {
    let a = array();
    match a {
        [.., (_x, _)] => {}
    }
    match a {
        //~^ ERROR [E0382]
        [_, _, ref _y @ ..] => {}
    }
}

fn move_out_by_subslice_and_const_index_field() {
    let a = array();
    match a {
        [_y @ .., _, _] => {}
    }
    match a {
        [(ref _x, _), _, _] => {} //~ ERROR [E0382]
    }
}

fn move_out_by_subslice_and_const_index_end_field() {
    let a = array();
    match a {
        [_, _, _y @ ..] => {}
    }
    match a {
        [.., (ref _x, _)] => {} //~ ERROR [E0382]
    }
}

// Slice + Slice

fn move_out_by_subslice_and_subslice() {
    let a = array();
    match a {
        [x @ .., _] => {}
    }
    match a {
        //~^ ERROR [E0382]
        [_, ref _y @ ..] => {}
    }
}

// Move + Assign

fn move_out_and_assign_end() {
    let mut a = array();
    match a {
        [_, _, _x] => {}
    }
    a[2] = Default::default(); //~ ERROR [E0382]
}

fn move_out_and_assign_end_field() {
    let mut a = array();
    match a {
        [_, _, (_x, _)] => {}
    }
    a[2].1 = Default::default(); //~ ERROR [E0382]
}

fn move_out_slice_and_assign_end() {
    let mut a = array();
    match a {
        [_, _, _x @ ..] => {}
    }
    a[0] = Default::default(); //~ ERROR [E0382]
}

fn move_out_slice_and_assign_end_field() {
    let mut a = array();
    match a {
        [_, _, _x @ ..] => {}
    }
    a[0].1 = Default::default(); //~ ERROR [E0382]
}

fn main() {}