1 // Tests that two closures cannot simultaneously have mutable
2 // and immutable access to the variable. Issue #6801.
4 // ignore-tidy-linelength
6 //[mir]compile-flags: -Z borrowck=mir
8 #![feature(box_syntax)]
10 fn get(x: &isize) -> isize {
14 fn set(x: &mut isize) {
21 let c2 = || x * 5; //[ast]~ ERROR cannot borrow `x`
22 //[mir]~^ ERROR cannot borrow `x` as immutable because it is also borrowed as mutable
28 let c1 = || set(&mut x);
29 let c2 = || get(&x); //[ast]~ ERROR cannot borrow `x`
30 //[mir]~^ ERROR cannot borrow `x` as immutable because it is also borrowed as mutable
36 let c1 = || set(&mut x);
37 let c2 = || x * 5; //[ast]~ ERROR cannot borrow `x`
38 //[mir]~^ ERROR cannot borrow `x` as immutable because it is also borrowed as mutable
45 x = 5; //[ast]~ ERROR cannot assign
46 //[mir]~^ ERROR cannot assign to `x` because it is borrowed
53 x = 5; //[ast]~ ERROR cannot assign
54 //[mir]~^ ERROR cannot assign to `x` because it is borrowed
59 let mut x: Box<_> = box 3;
61 *x = 5; //[ast]~ ERROR cannot assign to `*x`
62 //[mir]~^ ERROR cannot assign to `*x` because it is borrowed
71 let mut x: Box<_> = box Foo { f: box 3 };
72 let c1 = || get(&*x.f);
73 *x.f = 5; //[ast]~ ERROR cannot assign to `*x.f`
74 //[mir]~^ ERROR cannot assign to `*x.f` because it is borrowed
83 let mut x: Box<_> = box Foo { f: box 3 };
84 let c1 = || get(&*x.f);
85 let c2 = || *x.f = 5; //[ast]~ ERROR cannot borrow `x` as mutable
86 //[mir]~^ ERROR cannot borrow `x` as mutable because it is also borrowed as immutable