blob: 3eba9c4d431a203daad5157beefcce7a1b9d4429 [file] [log] [blame]
// Test that even unboxed closures that are capable of mutating their
// environment cannot mutate captured variables that have not been
// declared mutable (#18335)
fn set(x: &mut usize) { *x = 0; }
fn main() {
let x = 0;
move || x = 1; //~ ERROR cannot assign
move || set(&mut x); //~ ERROR cannot borrow
move || x = 1; //~ ERROR cannot assign
move || set(&mut x); //~ ERROR cannot borrow
|| x = 1; //~ ERROR cannot assign
|| set(&mut x); //~ ERROR cannot borrow
|| x = 1; //~ ERROR cannot assign
|| set(&mut x); //~ ERROR cannot borrow
}