]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-move-out-from-array-no-overlap-match.rs
Auto merge of #67731 - matthewjasper:drop-in-place-reclimit, r=eddyb
[rust.git] / src / test / ui / borrowck / borrowck-move-out-from-array-no-overlap-match.rs
1 // Due to #53114, which causes a "read" of the `_` patterns,
2 // the borrow-checker refuses this code, while it should probably be allowed.
3 // Once the bug is fixed, the test, which is derived from a
4 // passing test for `let` statements, should become check-pass.
5
6 #![feature(slice_patterns)]
7
8 fn array() -> [(String, String); 3] {
9     Default::default()
10 }
11
12 // Const Index + Const Index
13
14 fn move_out_from_begin_and_one_from_end() {
15     let a = array();
16     match a {
17         [_, _, _x] => {}
18     }
19     match a {
20         //~^ ERROR use of moved value
21         [.., _y, _] => {}
22     }
23 }
24
25 fn move_out_from_begin_field_and_end_field() {
26     let a = array();
27     match a {
28         [_, _, (_x, _)] => {}
29     }
30     match a {
31         //~^ ERROR use of moved value
32         [.., (_, _y)] => {}
33     }
34 }
35
36 // Const Index + Slice
37
38 fn move_out_by_const_index_and_subslice() {
39     let a = array();
40     match a {
41         [_x, _, _] => {}
42     }
43     match a {
44         //~^ ERROR use of moved value
45         [_, _y @ ..] => {}
46     }
47 }
48
49 fn move_out_by_const_index_end_and_subslice() {
50     let a = array();
51     match a {
52         [.., _x] => {}
53     }
54     match a {
55         //~^ ERROR use of moved value
56         [_y @ .., _] => {}
57     }
58 }
59
60 fn move_out_by_const_index_field_and_subslice() {
61     let a = array();
62     match a {
63         [(_x, _), _, _] => {}
64     }
65     match a {
66         //~^ ERROR use of moved value
67         [_, _y @ ..] => {}
68     }
69 }
70
71 fn move_out_by_const_index_end_field_and_subslice() {
72     let a = array();
73     match a {
74         [.., (_x, _)] => {}
75     }
76     match a {
77         //~^ ERROR use of moved value
78         [_y @ .., _] => {}
79     }
80 }
81
82 fn move_out_by_const_subslice_and_index_field() {
83     let a = array();
84     match a {
85         [_, _y @ ..] => {}
86     }
87     match a {
88         //~^ ERROR use of moved value
89         [(_x, _), _, _] => {}
90     }
91 }
92
93 fn move_out_by_const_subslice_and_end_index_field() {
94     let a = array();
95     match a {
96         [_y @ .., _] => {}
97     }
98     match a {
99         //~^ ERROR use of moved value
100         [.., (_x, _)] => {}
101     }
102 }
103
104 // Slice + Slice
105
106 fn move_out_by_subslice_and_subslice() {
107     let a = array();
108     match a {
109         [x @ .., _, _] => {}
110     }
111     match a {
112         //~^ ERROR use of moved value
113         [_, _y @ ..] => {}
114     }
115 }
116
117 fn main() {}