]>
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 | ||
13 | struct A { | |
14 | x: Box<isize>, | |
15 | y: isize, | |
16 | } | |
17 | ||
18 | struct B { | |
19 | x: Box<isize>, | |
20 | y: Box<isize>, | |
21 | } | |
22 | ||
23 | struct C { | |
24 | x: Box<A>, | |
25 | y: isize, | |
26 | } | |
27 | ||
28 | struct D { | |
29 | x: Box<A>, | |
30 | y: Box<isize>, | |
31 | } | |
32 | ||
33 | fn copy_after_move() { | |
c34b1796 | 34 | let a: Box<_> = box A { x: box 0, y: 1 }; |
1a4d82fc | 35 | let _x = a.x; |
a7813a04 | 36 | //~^ value moved here |
1a4d82fc | 37 | let _y = a.y; //~ ERROR use of moved |
a7813a04 XL |
38 | //~^ move occurs because `a.x` has type `Box<isize>` |
39 | //~| value used here after move | |
1a4d82fc JJ |
40 | } |
41 | ||
42 | fn move_after_move() { | |
c34b1796 | 43 | let a: Box<_> = box B { x: box 0, y: box 1 }; |
1a4d82fc | 44 | let _x = a.x; |
a7813a04 | 45 | //~^ value moved here |
1a4d82fc | 46 | let _y = a.y; //~ ERROR use of moved |
a7813a04 XL |
47 | //~^ move occurs because `a.x` has type `Box<isize>` |
48 | //~| value used here after move | |
1a4d82fc JJ |
49 | } |
50 | ||
51 | fn borrow_after_move() { | |
c34b1796 | 52 | let a: Box<_> = box A { x: box 0, y: 1 }; |
1a4d82fc | 53 | let _x = a.x; |
a7813a04 | 54 | //~^ value moved here |
1a4d82fc | 55 | let _y = &a.y; //~ ERROR use of moved |
a7813a04 XL |
56 | //~^ move occurs because `a.x` has type `Box<isize>` |
57 | //~| value used here after move | |
1a4d82fc JJ |
58 | } |
59 | ||
60 | fn move_after_borrow() { | |
c34b1796 | 61 | let a: Box<_> = box B { x: box 0, y: box 1 }; |
1a4d82fc | 62 | let _x = &a.x; |
54a0048b | 63 | //~^ NOTE borrow of `a.x` occurs here |
a7813a04 XL |
64 | let _y = a.y; |
65 | //~^ ERROR cannot move | |
66 | //~| move out of | |
1a4d82fc JJ |
67 | } |
68 | ||
69 | fn copy_after_mut_borrow() { | |
c34b1796 | 70 | let mut a: Box<_> = box A { x: box 0, y: 1 }; |
1a4d82fc | 71 | let _x = &mut a.x; |
54a0048b | 72 | //~^ NOTE borrow of `a.x` occurs here |
1a4d82fc | 73 | let _y = a.y; //~ ERROR cannot use |
9e0c209e | 74 | //~^ NOTE use of borrowed `a.x` |
1a4d82fc JJ |
75 | } |
76 | ||
77 | fn move_after_mut_borrow() { | |
c34b1796 | 78 | let mut a: Box<_> = box B { x: box 0, y: box 1 }; |
1a4d82fc | 79 | let _x = &mut a.x; |
54a0048b | 80 | //~^ NOTE borrow of `a.x` occurs here |
a7813a04 XL |
81 | let _y = a.y; |
82 | //~^ ERROR cannot move | |
83 | //~| move out of | |
1a4d82fc JJ |
84 | } |
85 | ||
86 | fn borrow_after_mut_borrow() { | |
c34b1796 | 87 | let mut a: Box<_> = box A { x: box 0, y: 1 }; |
1a4d82fc | 88 | let _x = &mut a.x; |
a7813a04 | 89 | //~^ NOTE mutable borrow occurs here (via `a.x`) |
1a4d82fc | 90 | let _y = &a.y; //~ ERROR cannot borrow |
a7813a04 | 91 | //~^ immutable borrow occurs here (via `a.y`) |
1a4d82fc | 92 | } |
a7813a04 | 93 | //~^ NOTE mutable borrow ends here |
1a4d82fc JJ |
94 | |
95 | fn mut_borrow_after_borrow() { | |
c34b1796 | 96 | let mut a: Box<_> = box A { x: box 0, y: 1 }; |
1a4d82fc | 97 | let _x = &a.x; |
a7813a04 | 98 | //~^ NOTE immutable borrow occurs here (via `a.x`) |
1a4d82fc | 99 | let _y = &mut a.y; //~ ERROR cannot borrow |
a7813a04 | 100 | //~^ mutable borrow occurs here (via `a.y`) |
1a4d82fc | 101 | } |
a7813a04 | 102 | //~^ NOTE immutable borrow ends here |
1a4d82fc JJ |
103 | |
104 | fn copy_after_move_nested() { | |
c34b1796 | 105 | let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; |
1a4d82fc | 106 | let _x = a.x.x; |
a7813a04 | 107 | //~^ value moved here |
1a4d82fc | 108 | let _y = a.y; //~ ERROR use of collaterally moved |
a7813a04 XL |
109 | //~^ NOTE move occurs because `a.x.x` has type `Box<isize>` |
110 | //~| value used here after move | |
1a4d82fc JJ |
111 | } |
112 | ||
113 | fn move_after_move_nested() { | |
c34b1796 | 114 | let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 }; |
1a4d82fc | 115 | let _x = a.x.x; |
a7813a04 | 116 | //~^ value moved here |
1a4d82fc | 117 | let _y = a.y; //~ ERROR use of collaterally moved |
a7813a04 XL |
118 | //~^ NOTE move occurs because `a.x.x` has type `Box<isize>` |
119 | //~| value used here after move | |
1a4d82fc JJ |
120 | } |
121 | ||
122 | fn borrow_after_move_nested() { | |
c34b1796 | 123 | let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; |
1a4d82fc | 124 | let _x = a.x.x; |
a7813a04 | 125 | //~^ value moved here |
1a4d82fc | 126 | let _y = &a.y; //~ ERROR use of collaterally moved |
a7813a04 XL |
127 | //~^ NOTE move occurs because `a.x.x` has type `Box<isize>` |
128 | //~| value used here after move | |
1a4d82fc JJ |
129 | } |
130 | ||
131 | fn move_after_borrow_nested() { | |
c34b1796 | 132 | let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 }; |
1a4d82fc | 133 | let _x = &a.x.x; |
a7813a04 XL |
134 | //~^ borrow of `a.x.x` occurs here |
135 | let _y = a.y; | |
136 | //~^ ERROR cannot move | |
137 | //~| move out of | |
1a4d82fc JJ |
138 | } |
139 | ||
140 | fn copy_after_mut_borrow_nested() { | |
c34b1796 | 141 | let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; |
1a4d82fc | 142 | let _x = &mut a.x.x; |
54a0048b | 143 | //~^ NOTE borrow of `a.x.x` occurs here |
1a4d82fc | 144 | let _y = a.y; //~ ERROR cannot use |
9e0c209e | 145 | //~^ NOTE use of borrowed `a.x.x` |
1a4d82fc JJ |
146 | } |
147 | ||
148 | fn move_after_mut_borrow_nested() { | |
c34b1796 | 149 | let mut a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 }; |
1a4d82fc | 150 | let _x = &mut a.x.x; |
54a0048b | 151 | //~^ NOTE borrow of `a.x.x` occurs here |
a7813a04 XL |
152 | let _y = a.y; |
153 | //~^ ERROR cannot move | |
154 | //~| move out of | |
1a4d82fc JJ |
155 | } |
156 | ||
157 | fn borrow_after_mut_borrow_nested() { | |
c34b1796 | 158 | let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; |
1a4d82fc | 159 | let _x = &mut a.x.x; |
a7813a04 | 160 | //~^ mutable borrow occurs here |
1a4d82fc | 161 | let _y = &a.y; //~ ERROR cannot borrow |
a7813a04 | 162 | //~^ immutable borrow occurs here |
1a4d82fc | 163 | } |
a7813a04 | 164 | //~^ NOTE mutable borrow ends here |
1a4d82fc JJ |
165 | |
166 | fn mut_borrow_after_borrow_nested() { | |
c34b1796 | 167 | let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; |
1a4d82fc | 168 | let _x = &a.x.x; |
a7813a04 | 169 | //~^ immutable borrow occurs here |
1a4d82fc | 170 | let _y = &mut a.y; //~ ERROR cannot borrow |
a7813a04 | 171 | //~^ mutable borrow occurs here |
1a4d82fc | 172 | } |
a7813a04 | 173 | //~^ NOTE immutable borrow ends here |
1a4d82fc JJ |
174 | |
175 | fn main() { | |
176 | copy_after_move(); | |
177 | move_after_move(); | |
178 | borrow_after_move(); | |
179 | ||
180 | move_after_borrow(); | |
181 | ||
182 | copy_after_mut_borrow(); | |
183 | move_after_mut_borrow(); | |
184 | borrow_after_mut_borrow(); | |
185 | mut_borrow_after_borrow(); | |
186 | ||
187 | copy_after_move_nested(); | |
188 | move_after_move_nested(); | |
189 | borrow_after_move_nested(); | |
190 | ||
191 | move_after_borrow_nested(); | |
192 | ||
193 | copy_after_mut_borrow_nested(); | |
194 | move_after_mut_borrow_nested(); | |
195 | borrow_after_mut_borrow_nested(); | |
196 | mut_borrow_after_borrow_nested(); | |
197 | } |