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 // Tests that two closures cannot simultaneously have mutable
12 // and immutable access to the variable. Issue #6801.
14 #![feature(box_syntax)]
16 fn get(x: &isize) -> isize {
20 fn set(x: &mut isize) {
26 let c1 = |&mut:| x = 4;
27 let c2 = |&mut:| x * 5; //~ ERROR cannot borrow `x`
32 let c1 = |&mut:| set(&mut x);
33 let c2 = |&mut:| get(&x); //~ ERROR cannot borrow `x`
38 let c1 = |&mut:| set(&mut x);
39 let c2 = |&mut:| x * 5; //~ ERROR cannot borrow `x`
44 let c2 = |&mut:| x * 5;
45 x = 5; //~ ERROR cannot assign
50 let c1 = |&mut:| get(&x);
51 x = 5; //~ ERROR cannot assign
56 let c1 = |&mut:| get(&*x);
57 *x = 5; //~ ERROR cannot assign
65 let mut x = box Foo { f: box 3 };
66 let c1 = |&mut:| get(&*x.f);
67 *x.f = 5; //~ ERROR cannot assign to `*x.f`
75 let mut x = box Foo { f: box 3 };
76 let c1 = |&mut:| get(&*x.f);
77 let c2 = |&mut:| *x.f = 5; //~ ERROR cannot borrow `x` as mutable