]> git.proxmox.com Git - rustc.git/blob - src/test/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs
Update unsuspicious file list
[rustc.git] / src / test / ui / borrowck / bindings-after-at-or-patterns-slice-patterns-box-patterns.rs
1 // Tests using a combination of pattern features has the expected borrow checking behavior
2 #![feature(box_patterns)]
3
4 enum Test {
5 Foo,
6 Bar,
7 _Baz,
8 }
9
10 // bindings_after_at + slice_patterns
11
12 fn bindings_after_at_slice_patterns_move_binding(x: [String; 4]) {
13 match x {
14 a @ [.., _] => (),
15 _ => (),
16 };
17
18 &x;
19 //~^ ERROR borrow of moved value
20 }
21
22 fn bindings_after_at_slice_patterns_borrows_binding_mut(mut x: [String; 4]) {
23 let r = match x {
24 ref mut foo @ [.., _] => Some(foo),
25 _ => None,
26 };
27
28 &x;
29 //~^ ERROR cannot borrow
30
31 drop(r);
32 }
33
34 fn bindings_after_at_slice_patterns_borrows_slice_mut1(mut x: [String; 4]) {
35 let r = match x {
36 ref foo @ [.., ref mut bar] => (),
37 //~^ ERROR cannot borrow
38 _ => (),
39 };
40
41 drop(r);
42 }
43
44 fn bindings_after_at_slice_patterns_borrows_slice_mut2(mut x: [String; 4]) {
45 let r = match x {
46 [ref foo @ .., ref bar] => Some(foo),
47 _ => None,
48 };
49
50 &mut x;
51 //~^ ERROR cannot borrow
52
53 drop(r);
54 }
55
56 fn bindings_after_at_slice_patterns_borrows_both(mut x: [String; 4]) {
57 let r = match x {
58 ref foo @ [.., ref bar] => Some(foo),
59 _ => None,
60 };
61
62 &mut x;
63 //~^ ERROR cannot borrow
64
65 drop(r);
66 }
67
68 // bindings_after_at + or_patterns
69
70 fn bindings_after_at_or_patterns_move(x: Option<Test>) {
71 match x {
72 foo @ Some(Test::Foo | Test::Bar) => (),
73 _ => (),
74 }
75
76 &x;
77 //~^ ERROR borrow of moved value
78 }
79
80 fn bindings_after_at_or_patterns_borrows(mut x: Option<Test>) {
81 let r = match x {
82 ref foo @ Some(Test::Foo | Test::Bar) => Some(foo),
83 _ => None,
84 };
85
86 &mut x;
87 //~^ ERROR cannot borrow
88
89 drop(r);
90 }
91
92 fn bindings_after_at_or_patterns_borrows_mut(mut x: Option<Test>) {
93 let r = match x {
94 ref mut foo @ Some(Test::Foo | Test::Bar) => Some(foo),
95 _ => None,
96 };
97
98 &x;
99 //~^ ERROR cannot borrow
100
101 drop(r);
102 }
103
104 // bindings_after_at + box_patterns
105
106 fn bindings_after_at_box_patterns_borrows_both(mut x: Option<Box<String>>) {
107 let r = match x {
108 ref foo @ Some(box ref s) => Some(foo),
109 _ => None,
110 };
111
112 &mut x;
113 //~^ ERROR cannot borrow
114
115 drop(r);
116 }
117
118 fn bindings_after_at_box_patterns_borrows_mut(mut x: Option<Box<String>>) {
119 match x {
120 ref foo @ Some(box ref mut s) => (),
121 //~^ ERROR cannot borrow
122 _ => (),
123 };
124 }
125
126 // bindings_after_at + slice_patterns + or_patterns
127
128 fn bindings_after_at_slice_patterns_or_patterns_moves(x: [Option<Test>; 4]) {
129 match x {
130 a @ [.., Some(Test::Foo | Test::Bar)] => (),
131 _ => (),
132 };
133
134 &x;
135 //~^ ERROR borrow of moved value
136 }
137
138 fn bindings_after_at_slice_patterns_or_patterns_borrows_binding(mut x: [Option<Test>; 4]) {
139 let r = match x {
140 ref a @ [ref b @ .., Some(Test::Foo | Test::Bar)] => Some(a),
141 _ => None,
142 };
143
144 &mut x;
145 //~^ ERROR cannot borrow
146
147 drop(r);
148 }
149
150 fn bindings_after_at_slice_patterns_or_patterns_borrows_slice(mut x: [Option<Test>; 4]) {
151 let r = match x {
152 ref a @ [ref b @ .., Some(Test::Foo | Test::Bar)] => Some(b),
153 _ => None,
154 };
155
156 &mut x;
157 //~^ ERROR cannot borrow
158
159 drop(r);
160 }
161
162 // bindings_after_at + slice_patterns + box_patterns
163
164 fn bindings_after_at_slice_patterns_box_patterns_borrows(mut x: [Option<Box<String>>; 4]) {
165 let r = match x {
166 [_, ref a @ Some(box ref b), ..] => Some(a),
167 _ => None,
168 };
169
170 &mut x;
171 //~^ ERROR cannot borrow
172
173 drop(r);
174 }
175
176 // bindings_after_at + slice_patterns + or_patterns + box_patterns
177
178 fn bindings_after_at_slice_patterns_or_patterns_box_patterns_borrows(
179 mut x: [Option<Box<Test>>; 4]
180 ) {
181 let r = match x {
182 [_, ref a @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
183 _ => None,
184 };
185
186 &mut x;
187 //~^ ERROR cannot borrow
188
189 drop(r);
190 }
191
192 fn bindings_after_at_slice_patterns_or_patterns_box_patterns_borrows_mut(
193 mut x: [Option<Box<Test>>; 4]
194 ) {
195 let r = match x {
196 [_, ref mut a @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
197 _ => None,
198 };
199
200 &x;
201 //~^ ERROR cannot borrow
202
203 drop(r);
204 }
205
206 fn bindings_after_at_slice_patterns_or_patterns_box_patterns_borrows_binding(
207 mut x: [Option<Box<Test>>; 4]
208 ) {
209 let r = match x {
210 ref a @ [_, ref b @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
211 _ => None,
212 };
213
214 &mut x;
215 //~^ ERROR cannot borrow
216
217 drop(r);
218 }
219
220 fn main() {}