2014-10-25 23:27:54 -05:00
|
|
|
// Test that even unboxed closures that are capable of mutating their
|
|
|
|
// environment cannot mutate captured variables that have not been
|
|
|
|
// declared mutable (#18335)
|
|
|
|
|
2015-01-08 05:02:42 -06:00
|
|
|
fn set(x: &mut usize) { *x = 0; }
|
2014-10-25 23:27:54 -05:00
|
|
|
|
|
|
|
fn main() {
|
2015-03-03 02:42:26 -06:00
|
|
|
let x = 0;
|
2015-02-01 11:44:15 -06:00
|
|
|
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
|
2019-04-22 02:40:08 -05:00
|
|
|
|| set(&mut x); //~ ERROR cannot borrow
|
2015-02-01 11:44:15 -06:00
|
|
|
|| x = 1; //~ ERROR cannot assign
|
2019-04-22 02:40:08 -05:00
|
|
|
|| set(&mut x); //~ ERROR cannot borrow
|
2014-10-25 23:27:54 -05:00
|
|
|
}
|