2014-10-25 21:27:54 -07: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 22:02:42 +11:00
|
|
|
fn set(x: &mut usize) { *x = 0; }
|
2014-10-25 21:27:54 -07:00
|
|
|
|
|
|
|
fn main() {
|
2015-03-03 10:42:26 +02:00
|
|
|
let x = 0;
|
2015-02-01 12:44:15 -05: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 08:40:08 +01:00
|
|
|
|| set(&mut x); //~ ERROR cannot borrow
|
2015-02-01 12:44:15 -05:00
|
|
|
|| x = 1; //~ ERROR cannot assign
|
2019-04-22 08:40:08 +01:00
|
|
|
|| set(&mut x); //~ ERROR cannot borrow
|
2014-10-25 21:27:54 -07:00
|
|
|
}
|