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.
15 fn get(x: &int) -> int {
26 let c2 = || x * 5; //~ ERROR cannot borrow `x`
31 let c1 = || set(&mut x);
32 let c2 = || get(&x); //~ ERROR cannot borrow `x`
37 let c1 = || set(&mut x);
38 let c2 = || x * 5; //~ ERROR cannot borrow `x`
44 x = 5; //~ ERROR cannot assign
50 x = 5; //~ ERROR cannot assign
56 *x = 5; //~ ERROR cannot assign
64 let mut x = box Foo { f: box 3 };
65 let c1 = || get(&*x.f);
66 *x.f = 5; //~ ERROR cannot assign to `*x.f`
74 let mut x = box Foo { f: box 3 };
75 let c1 = || get(&*x.f);
76 let c2 = || *x.f = 5; //~ ERROR cannot borrow `x` as mutable