]> git.proxmox.com Git - rustc.git/blob - tests/ui/borrowck/borrowck-move-out-from-array-use-no-overlap-match.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / borrowck / borrowck-move-out-from-array-use-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 fn array() -> [(String, String); 3] {
7 Default::default()
8 }
9
10 // Const Index + Const Index
11
12 fn move_out_from_begin_and_one_from_end() {
13 let a = array();
14 match a {
15 [_, _, _x] => {}
16 }
17 match a {
18 //~^ ERROR use of partially moved value
19 [.., ref _y, _] => {}
20 }
21 }
22
23 fn move_out_from_begin_field_and_end_field() {
24 let a = array();
25 match a {
26 [_, _, (_x, _)] => {}
27 }
28 match a {
29 //~^ ERROR use of partially moved value
30 [.., (_, ref _y)] => {}
31 }
32 }
33
34 // Const Index + Slice
35
36 fn move_out_by_const_index_and_subslice() {
37 let a = array();
38 match a {
39 [_x, _, _] => {}
40 }
41 match a {
42 //~^ ERROR use of partially moved value
43 [_, ref _y @ ..] => {}
44 }
45 }
46
47 fn move_out_by_const_index_end_and_subslice() {
48 let a = array();
49 match a {
50 [.., _x] => {}
51 }
52 match a {
53 //~^ ERROR use of partially moved value
54 [ref _y @ .., _] => {}
55 }
56 }
57
58 fn move_out_by_const_index_field_and_subslice() {
59 let a = array();
60 match a {
61 [(_x, _), _, _] => {}
62 }
63 match a {
64 //~^ ERROR use of partially moved value
65 [_, ref _y @ ..] => {}
66 }
67 }
68
69 fn move_out_by_const_index_end_field_and_subslice() {
70 let a = array();
71 match a {
72 [.., (_x, _)] => {}
73 }
74 match a {
75 //~^ ERROR use of partially moved value
76 [ref _y @ .., _] => {}
77 }
78 }
79
80 fn move_out_by_const_subslice_and_index_field() {
81 let a = array();
82 match a {
83 [_, _y @ ..] => {}
84 }
85 match a {
86 //~^ ERROR use of partially moved value
87 [(ref _x, _), _, _] => {}
88 }
89 }
90
91 fn move_out_by_const_subslice_and_end_index_field() {
92 let a = array();
93 match a {
94 [_y @ .., _] => {}
95 }
96 match a {
97 //~^ ERROR use of partially moved value
98 [.., (ref _x, _)] => {}
99 }
100 }
101
102 // Slice + Slice
103
104 fn move_out_by_subslice_and_subslice() {
105 let a = array();
106 match a {
107 [x @ .., _, _] => {}
108 }
109 match a {
110 //~^ ERROR use of partially moved value
111 [_, ref _y @ ..] => {}
112 }
113 }
114
115 fn main() {}