1 // Tests that two closures cannot simultaneously have mutable
2 // and immutable access to the variable. Issue #6801.
4 fn get(x: &isize) -> isize {
8 fn set(x: &mut isize) {
18 //~^ ERROR cannot borrow `x` as immutable because it is also borrowed as mutable
24 let c1 = || set(&mut x);
26 //~^ ERROR cannot borrow `x` as immutable because it is also borrowed as mutable
32 let c1 = || set(&mut x);
34 //~^ ERROR cannot borrow `x` as immutable because it is also borrowed as mutable
42 //~^ ERROR cannot assign to `x` because it is borrowed
50 //~^ ERROR cannot assign to `x` because it is borrowed
55 let mut x: Box<_> = Box::new(3);
58 //~^ ERROR cannot assign to `*x` because it is borrowed
67 let mut x: Box<_> = Box::new(Foo { f: Box::new(3) });
68 let c1 = || get(&*x.f);
70 //~^ ERROR cannot assign to `*x.f` because it is borrowed
79 let mut x: Box<_> = Box::new(Foo { f: Box::new(3) });
80 let c1 = || get(&*x.f);
82 //~^ ERROR cannot borrow `x` as mutable because it is also borrowed as immutable