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.
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.
11 #![feature(box_syntax, rustc_attrs)]
33 fn copy_after_move() {
34 let a: Box<_> = box A { x: box 0, y: 1 };
37 let _y = a.y; //~ ERROR use of moved
38 //~^ move occurs because `a.x` has type `std::boxed::Box<isize>`
39 //~| value used here after move
42 fn move_after_move() {
43 let a: Box<_> = box B { x: box 0, y: box 1 };
46 let _y = a.y; //~ ERROR use of moved
47 //~^ move occurs because `a.x` has type `std::boxed::Box<isize>`
48 //~| value used here after move
51 fn borrow_after_move() {
52 let a: Box<_> = box A { x: box 0, y: 1 };
55 let _y = &a.y; //~ ERROR use of moved
56 //~^ move occurs because `a.x` has type `std::boxed::Box<isize>`
57 //~| value used here after move
60 fn move_after_borrow() {
61 let a: Box<_> = box B { x: box 0, y: box 1 };
64 //~^ ERROR cannot move
68 fn copy_after_mut_borrow() {
69 let mut a: Box<_> = box A { x: box 0, y: 1 };
71 let _y = a.y; //~ ERROR cannot use
74 fn move_after_mut_borrow() {
75 let mut a: Box<_> = box B { x: box 0, y: box 1 };
78 //~^ ERROR cannot move
82 fn borrow_after_mut_borrow() {
83 let mut a: Box<_> = box A { x: box 0, y: 1 };
85 let _y = &a.y; //~ ERROR cannot borrow
86 //~^ immutable borrow occurs here (via `a.y`)
89 fn mut_borrow_after_borrow() {
90 let mut a: Box<_> = box A { x: box 0, y: 1 };
92 let _y = &mut a.y; //~ ERROR cannot borrow
93 //~^ mutable borrow occurs here (via `a.y`)
96 fn copy_after_move_nested() {
97 let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
100 let _y = a.y; //~ ERROR use of collaterally moved
101 //~| value used here after move
104 fn move_after_move_nested() {
105 let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
107 //~^ value moved here
108 let _y = a.y; //~ ERROR use of collaterally moved
109 //~| value used here after move
112 fn borrow_after_move_nested() {
113 let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
115 //~^ value moved here
116 let _y = &a.y; //~ ERROR use of collaterally moved
117 //~| value used here after move
120 fn move_after_borrow_nested() {
121 let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
123 //~^ borrow of `a.x.x` occurs here
125 //~^ ERROR cannot move
129 fn copy_after_mut_borrow_nested() {
130 let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
132 let _y = a.y; //~ ERROR cannot use
135 fn move_after_mut_borrow_nested() {
136 let mut a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 };
139 //~^ ERROR cannot move
143 fn borrow_after_mut_borrow_nested() {
144 let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
146 //~^ mutable borrow occurs here
147 let _y = &a.y; //~ ERROR cannot borrow
148 //~^ immutable borrow occurs here
151 fn mut_borrow_after_borrow_nested() {
152 let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 };
154 //~^ immutable borrow occurs here
155 let _y = &mut a.y; //~ ERROR cannot borrow
156 //~^ mutable borrow occurs here
167 copy_after_mut_borrow();
168 move_after_mut_borrow();
169 borrow_after_mut_borrow();
170 mut_borrow_after_borrow();
172 copy_after_move_nested();
173 move_after_move_nested();
174 borrow_after_move_nested();
176 move_after_borrow_nested();
178 copy_after_mut_borrow_nested();
179 move_after_mut_borrow_nested();
180 borrow_after_mut_borrow_nested();
181 mut_borrow_after_borrow_nested();