rust/tests/ui/unboxed-closures/unboxed-closure-immutable-capture.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

18 lines
579 B
Rust
Raw Normal View History

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)
fn set(x: &mut usize) { *x = 0; }
2014-10-25 23:27:54 -05:00
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
2014-10-25 23:27:54 -05:00
}