1 // Tests that a closure which requires mutable access to the referent
2 // of an `&mut` requires a "unique" borrow -- that is, the variable to
3 // be borrowed (here, `x`) will not be borrowed *mutably*, but
4 // may be *immutable*, but we cannot allow
9 fn get(x: &isize) -> isize {
13 fn set(x: &mut isize) -> isize {
26 let c2 = || set(x); //~ ERROR closure requires unique access to `x`
32 let c2 = || { get(x); set(x); }; //~ ERROR closure requires unique access to `x`
38 let c2 = || set(x); //~ ERROR two closures require unique access to `x` at the same time
42 fn e(x: &'static mut isize) {
43 let c1 = |y: &'static mut isize| x = y;
44 //~^ ERROR cannot assign to `x`, as it is not declared as mutable
48 fn f(x: &'static mut isize) {
49 let c1 = || x = panic!(); // OK assignment is unreachable.