mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
18 lines
579 B
Rust
18 lines
579 B
Rust
// 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
|
|
}
|