Mutability

Variable bindings are immutable by default, but this can be overridden using the mut modifier.

1. fn main() {
2. let _immutable_binding = 1;
3. let mut mutable_binding = 1;

5. println!("Before mutation: {}", mutable_binding);

7. // Ok
8. mutable_binding += 1;

10. println!("After mutation: {}", mutable_binding);

12. // Error!
13. _immutable_binding += 1;
14. // FIXME ^ Comment out this line
15. }

The compiler will throw a detailed diagnostic about mutability errors.