]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
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 | #![feature(box_syntax)] | |
12 | ||
c34b1796 | 13 | #[derive(Copy, Clone)] |
1a4d82fc JJ |
14 | struct A { a: isize, b: isize } |
15 | ||
1a4d82fc JJ |
16 | struct B { a: isize, b: Box<isize> } |
17 | ||
18 | fn var_copy_after_var_borrow() { | |
19 | let mut x: isize = 1; | |
20 | let p = &mut x; | |
21 | drop(x); //~ ERROR cannot use `x` because it was mutably borrowed | |
22 | *p = 2; | |
23 | } | |
24 | ||
25 | fn var_copy_after_field_borrow() { | |
26 | let mut x = A { a: 1, b: 2 }; | |
27 | let p = &mut x.a; | |
28 | drop(x); //~ ERROR cannot use `x` because it was mutably borrowed | |
29 | *p = 3; | |
30 | } | |
31 | ||
32 | fn field_copy_after_var_borrow() { | |
33 | let mut x = A { a: 1, b: 2 }; | |
34 | let p = &mut x; | |
35 | drop(x.a); //~ ERROR cannot use `x.a` because it was mutably borrowed | |
36 | p.a = 3; | |
37 | } | |
38 | ||
39 | fn field_copy_after_field_borrow() { | |
40 | let mut x = A { a: 1, b: 2 }; | |
41 | let p = &mut x.a; | |
42 | drop(x.a); //~ ERROR cannot use `x.a` because it was mutably borrowed | |
43 | *p = 3; | |
44 | } | |
45 | ||
46 | fn fu_field_copy_after_var_borrow() { | |
47 | let mut x = A { a: 1, b: 2 }; | |
48 | let p = &mut x; | |
49 | let y = A { b: 3, .. x }; //~ ERROR cannot use `x.a` because it was mutably borrowed | |
50 | drop(y); | |
51 | p.a = 4; | |
52 | } | |
53 | ||
54 | fn fu_field_copy_after_field_borrow() { | |
55 | let mut x = A { a: 1, b: 2 }; | |
56 | let p = &mut x.a; | |
57 | let y = A { b: 3, .. x }; //~ ERROR cannot use `x.a` because it was mutably borrowed | |
58 | drop(y); | |
59 | *p = 4; | |
60 | } | |
61 | ||
62 | fn var_deref_after_var_borrow() { | |
63 | let mut x: Box<isize> = box 1; | |
64 | let p = &mut x; | |
65 | drop(*x); //~ ERROR cannot use `*x` because it was mutably borrowed | |
66 | **p = 2; | |
67 | } | |
68 | ||
69 | fn field_deref_after_var_borrow() { | |
70 | let mut x = B { a: 1, b: box 2 }; | |
71 | let p = &mut x; | |
72 | drop(*x.b); //~ ERROR cannot use `*x.b` because it was mutably borrowed | |
73 | p.a = 3; | |
74 | } | |
75 | ||
76 | fn field_deref_after_field_borrow() { | |
77 | let mut x = B { a: 1, b: box 2 }; | |
78 | let p = &mut x.b; | |
79 | drop(*x.b); //~ ERROR cannot use `*x.b` because it was mutably borrowed | |
80 | **p = 3; | |
81 | } | |
82 | ||
83 | fn main() { | |
84 | var_copy_after_var_borrow(); | |
85 | var_copy_after_field_borrow(); | |
86 | ||
87 | field_copy_after_var_borrow(); | |
88 | field_copy_after_field_borrow(); | |
89 | ||
90 | fu_field_copy_after_var_borrow(); | |
91 | fu_field_copy_after_field_borrow(); | |
92 | ||
93 | var_deref_after_var_borrow(); | |
94 | field_deref_after_var_borrow(); | |
95 | field_deref_after_field_borrow(); | |
96 | } |