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;
  4. println!("Before mutation: {}", mutable_binding);
  5. // Ok
  6. mutable_binding += 1;
  7. println!("After mutation: {}", mutable_binding);
  8. // Error!
  9. _immutable_binding += 1;
  10. // FIXME ^ Comment out this line
  11. }

The compiler will throw a detailed diagnostic about mutability errors.