1 // Copyright 2016 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 // ignore-tidy-linelength
13 //[mir]compile-flags: -Z borrowck=mir
15 #[derive(Clone, Copy)]
23 let mut u = U { b: 0 };
24 // Imm borrow, same field
37 let rma = &mut u.a; //[ast]~ ERROR cannot borrow `u.a` as mutable because it is also borrowed as immutable
38 //[mir]~^ ERROR cannot borrow `u.a` as mutable because it is also borrowed as immutable
43 u.a = 1; //[ast]~ ERROR cannot assign to `u.a` because it is borrowed
44 //[mir]~^ ERROR cannot assign to `u.a` because it is borrowed
47 // Imm borrow, other field
60 let rmb = &mut u.b; //[ast]~ ERROR cannot borrow `u` (via `u.b`) as mutable because `u` is also borrowed as immutable (via `u.a`)
61 //[mir]~^ ERROR cannot borrow `u.b` as mutable because it is also borrowed as immutable
66 u.b = 1; //[ast]~ ERROR cannot assign to `u.b` because it is borrowed
67 //[mir]~^ ERROR cannot assign to `u.b` because it is borrowed
70 // Mut borrow, same field
73 let ra = &u.a; //[ast]~ ERROR cannot borrow `u.a` as immutable because it is also borrowed as mutable
74 //[mir]~^ ERROR cannot borrow `u.a` as immutable because it is also borrowed as mutable
79 let a = u.a; //[ast]~ ERROR cannot use `u.a` because it was mutably borrowed
80 //[mir]~^ ERROR cannot use `u.a` because it was mutably borrowed
85 let rma2 = &mut u.a; //[ast]~ ERROR cannot borrow `u.a` as mutable more than once at a time
86 //[mir]~^ ERROR cannot borrow `u.a` as mutable more than once at a time
91 u.a = 1; //[ast]~ ERROR cannot assign to `u.a` because it is borrowed
92 //[mir]~^ ERROR cannot assign to `u.a` because it is borrowed
95 // Mut borrow, other field
98 let rb = &u.b; //[ast]~ ERROR cannot borrow `u` (via `u.b`) as immutable because `u` is also borrowed as mutable (via `u.a`)
99 //[mir]~^ ERROR cannot borrow `u.b` as immutable because it is also borrowed as mutable
104 let b = u.b; //[ast]~ ERROR cannot use `u.b` because it was mutably borrowed
105 //[mir]~^ ERROR cannot use `u.b` because it was mutably borrowed
111 let rmb2 = &mut u.b; //[ast]~ ERROR cannot borrow `u` (via `u.b`) as mutable more than once at a time
112 //[mir]~^ ERROR cannot borrow `u.b` as mutable more than once at a time
117 u.b = 1; //[ast]~ ERROR cannot assign to `u.b` because it is borrowed
118 //[mir]~^ ERROR cannot assign to `u.b` because it is borrowed