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 a closure which requires mutable access to the referent
12 // of an `&mut` requires a "unique" borrow -- that is, the variable to
13 // be borrowed (here, `x`) will not be borrowed *mutably*, but
14 // may be *immutable*, but we cannot allow
17 fn get(x: &int) -> int {
21 fn set(x: &mut int) -> int {
26 let c1 = |&mut:| get(x);
27 let c2 = |&mut:| get(x);
31 let c1 = |&mut:| get(x);
32 let c2 = |&mut:| set(x); //~ ERROR closure requires unique access to `x`
36 let c1 = |&mut:| get(x);
37 let c2 = |&mut:| { get(x); set(x); }; //~ ERROR closure requires unique access to `x`
41 let c1 = |&mut:| set(x);
42 let c2 = |&mut:| set(x); //~ ERROR closure requires unique access to `x`
46 let c1 = |&mut:| x = panic!(); //~ ERROR closure cannot assign to immutable local variable