- let
Variables are immutable
- Variables in Rust are immutable by default.
examples/variables/immutable-number/src/main.rs
fn main() { let num = 2; println!("{num}"); num = 3; println!("{num}"); }
error[E0384]: cannot assign twice to immutable variable `num` --> src/main.rs:5:5 | 2 | let num = 2; | --- | | | first assignment to `num` | help: consider making this binding mutable: `mut num` ... 5 | num = 3; | ^^^^^^^ cannot assign twice to immutable variable For more information about this error, try `rustc --explain E0384`. error: could not compile `immutable-number` (bin "immutable-number") due to 1 previous error