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