blob: 0925132f204f7b60bf6acf14bf6decf92b75af56 [file] [log] [blame] [view] [edit]
# Mutability
Variable bindings are immutable by default, but this can be overridden using
the `mut` modifier.
```rust,editable,ignore,mdbook-runnable
fn main() {
let _immutable_binding = 1;
let mut mutable_binding = 1;
println!("Before mutation: {}", mutable_binding);
// Ok
mutable_binding += 1;
println!("After mutation: {}", mutable_binding);
// Error!
_immutable_binding += 1;
// FIXME ^ Comment out this line
}
```
The compiler will throw a detailed diagnostic about mutability errors.