summaryrefslogtreecommitdiffstats
path: root/src/test/ui/unboxed-closures/unboxed-closure-immutable-capture.rs
blob: 3eba9c4d431a203daad5157beefcce7a1b9d4429 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 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; }

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
}