]> git.lizzy.rs Git - rust.git/blob - src/test/ui/unboxed-closures/unboxed-closure-immutable-capture.rs
Permit `#[deprecated]` in stdlib
[rust.git] / src / test / ui / unboxed-closures / unboxed-closure-immutable-capture.rs
1 // Test that even unboxed closures that are capable of mutating their
2 // environment cannot mutate captured variables that have not been
3 // declared mutable (#18335)
4
5 fn set(x: &mut usize) { *x = 0; }
6
7 fn main() {
8     let x = 0;
9     move || x = 1; //~ ERROR cannot assign
10     move || set(&mut x); //~ ERROR cannot borrow
11     move || x = 1; //~ ERROR cannot assign
12     move || set(&mut x); //~ ERROR cannot borrow
13     || x = 1; //~ ERROR cannot assign
14     || set(&mut x); //~ ERROR cannot borrow
15     || x = 1; //~ ERROR cannot assign
16     || set(&mut x); //~ ERROR cannot borrow
17 }