]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/borrowck/borrowck-field-sensitivity.rs
Convert unknown_features lint into an error
[rust.git] / src / test / run-pass / borrowck / borrowck-field-sensitivity.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // pretty-expanded FIXME #23616
12
13 #![feature(box_syntax)]
14
15 struct A { a: isize, b: Box<isize> }
16 struct B { a: Box<isize>, b: Box<isize> }
17
18 fn move_after_copy() {
19     let x = A { a: 1, b: box 2 };
20     drop(x.a);
21     drop(x.b);
22 }
23
24 fn move_after_fu_copy() {
25     let x = A { a: 1, b: box 2 };
26     let _y = A { b: box 3, .. x };
27     drop(x.b);
28 }
29
30 fn fu_move_after_copy() {
31     let x = A { a: 1, b: box 2 };
32     drop(x.a);
33     let _y = A { a: 3, .. x };
34 }
35
36 fn fu_move_after_fu_copy() {
37     let x = A { a: 1, b: box 2 };
38     let _y = A { b: box 3, .. x };
39     let _z = A { a: 4, .. x };
40 }
41
42 fn copy_after_move() {
43     let x = A { a: 1, b: box 2 };
44     drop(x.b);
45     drop(x.a);
46 }
47
48 fn copy_after_fu_move() {
49     let x = A { a: 1, b: box 2 };
50     let y = A { a: 3, .. x };
51     drop(x.a);
52 }
53
54 fn fu_copy_after_move() {
55     let x = A { a: 1, b: box 2 };
56     drop(x.b);
57     let _y = A { b: box 3, .. x };
58 }
59
60 fn fu_copy_after_fu_move() {
61     let x = A { a: 1, b: box 2 };
62     let _y = A { a: 3, .. x };
63     let _z = A { b: box 3, .. x };
64 }
65
66 fn borrow_after_move() {
67     let x = A { a: 1, b: box 2 };
68     drop(x.b);
69     let p = &x.a;
70     drop(*p);
71 }
72
73 fn borrow_after_fu_move() {
74     let x = A { a: 1, b: box 2 };
75     let _y = A { a: 3, .. x };
76     let p = &x.a;
77     drop(*p);
78 }
79
80 fn move_after_borrow() {
81     let x = A { a: 1, b: box 2 };
82     let p = &x.a;
83     drop(x.b);
84     drop(*p);
85 }
86
87 fn fu_move_after_borrow() {
88     let x = A { a: 1, b: box 2 };
89     let p = &x.a;
90     let _y = A { a: 3, .. x };
91     drop(*p);
92 }
93
94 fn mut_borrow_after_mut_borrow() {
95     let mut x = A { a: 1, b: box 2 };
96     let p = &mut x.a;
97     let q = &mut x.b;
98     drop(*p);
99     drop(**q);
100 }
101
102 fn move_after_move() {
103     let x = B { a: box 1, b: box 2 };
104     drop(x.a);
105     drop(x.b);
106 }
107
108 fn move_after_fu_move() {
109     let x = B { a: box 1, b: box 2 };
110     let y = B { a: box 3, .. x };
111     drop(x.a);
112 }
113
114 fn fu_move_after_move() {
115     let x = B { a: box 1, b: box 2 };
116     drop(x.a);
117     let z = B { a: box 3, .. x };
118     drop(z.b);
119 }
120
121 fn fu_move_after_fu_move() {
122     let x = B { a: box 1, b: box 2 };
123     let _y = B { b: box 3, .. x };
124     let _z = B { a: box 4, .. x };
125 }
126
127 fn copy_after_assign_after_move() {
128     let mut x = A { a: 1, b: box 2 };
129     drop(x.b);
130     x = A { a: 3, b: box 4 };
131     drop(*x.b);
132 }
133
134 fn copy_after_assign_after_fu_move() {
135     let mut x = A { a: 1, b: box 2 };
136     let _y = A { a: 3, .. x };
137     x = A { a: 3, b: box 4 };
138     drop(*x.b);
139 }
140
141 fn copy_after_field_assign_after_move() {
142     let mut x = A { a: 1, b: box 2 };
143     drop(x.b);
144     x.b = box 3;
145     drop(*x.b);
146 }
147
148 fn copy_after_field_assign_after_fu_move() {
149     let mut x = A { a: 1, b: box 2 };
150     let _y = A { a: 3, .. x };
151     x.b = box 3;
152     drop(*x.b);
153 }
154
155 fn borrow_after_assign_after_move() {
156     let mut x = A { a: 1, b: box 2 };
157     drop(x.b);
158     x = A { a: 3, b: box 4 };
159     let p = &x.b;
160     drop(**p);
161 }
162
163 fn borrow_after_assign_after_fu_move() {
164     let mut x = A { a: 1, b: box 2 };
165     let _y = A { a: 3, .. x };
166     x = A { a: 3, b: box 4 };
167     let p = &x.b;
168     drop(**p);
169 }
170
171 fn borrow_after_field_assign_after_move() {
172     let mut x = A { a: 1, b: box 2 };
173     drop(x.b);
174     x.b = box 3;
175     let p = &x.b;
176     drop(**p);
177 }
178
179 fn borrow_after_field_assign_after_fu_move() {
180     let mut x = A { a: 1, b: box 2 };
181     let _y = A { a: 3, .. x };
182     x.b = box 3;
183     let p = &x.b;
184     drop(**p);
185 }
186
187 fn move_after_assign_after_move() {
188     let mut x = A { a: 1, b: box 2 };
189     let _y = x.b;
190     x = A { a: 3, b: box 4 };
191     drop(x.b);
192 }
193
194 fn move_after_assign_after_fu_move() {
195     let mut x = A { a: 1, b: box 2 };
196     let _y = A { a: 3, .. x };
197     x = A { a: 3, b: box 4 };
198     drop(x.b);
199 }
200
201 fn move_after_field_assign_after_move() {
202     let mut x = A { a: 1, b: box 2 };
203     drop(x.b);
204     x.b = box 3;
205     drop(x.b);
206 }
207
208 fn move_after_field_assign_after_fu_move() {
209     let mut x = A { a: 1, b: box 2 };
210     let _y = A { a: 3, .. x };
211     x.b = box 3;
212     drop(x.b);
213 }
214
215 fn copy_after_assign_after_uninit() {
216     let mut x: A;
217     x = A { a: 1, b: box 2 };
218     drop(x.a);
219 }
220
221 fn borrow_after_assign_after_uninit() {
222     let mut x: A;
223     x = A { a: 1, b: box 2 };
224     let p = &x.a;
225     drop(*p);
226 }
227
228 fn move_after_assign_after_uninit() {
229     let mut x: A;
230     x = A { a: 1, b: box 2 };
231     drop(x.b);
232 }
233
234 fn main() {
235     move_after_copy();
236     move_after_fu_copy();
237     fu_move_after_copy();
238     fu_move_after_fu_copy();
239     copy_after_move();
240     copy_after_fu_move();
241     fu_copy_after_move();
242     fu_copy_after_fu_move();
243
244     borrow_after_move();
245     borrow_after_fu_move();
246     move_after_borrow();
247     fu_move_after_borrow();
248     mut_borrow_after_mut_borrow();
249
250     move_after_move();
251     move_after_fu_move();
252     fu_move_after_move();
253     fu_move_after_fu_move();
254
255     copy_after_assign_after_move();
256     copy_after_assign_after_fu_move();
257     copy_after_field_assign_after_move();
258     copy_after_field_assign_after_fu_move();
259
260     borrow_after_assign_after_move();
261     borrow_after_assign_after_fu_move();
262     borrow_after_field_assign_after_move();
263     borrow_after_field_assign_after_fu_move();
264
265     move_after_assign_after_move();
266     move_after_assign_after_fu_move();
267     move_after_field_assign_after_move();
268     move_after_field_assign_after_fu_move();
269
270     copy_after_assign_after_uninit();
271     borrow_after_assign_after_uninit();
272     move_after_assign_after_uninit();
273 }