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