If you own a variable, you can mutate it. If it wasn’t declared with
mut, you can reassign it with local
let mut var = ... and mutate it anyway.
The main point here is ownership: as long as you own a variable (and you are not borrowing it at the moment) you can mutate it one way or another.
Update: I think I was not clear enough here. The “mutability” of an owned variable is property of the variable itself, not a data behind it. When you say
let mut x = y; where y is not mutable, you create a new mutable variable x and bind it to the data bound to y. That is you can’t mutate a piece of data behind of immutable variable y, but you can do it behind mutable variable x. The data can be the same, but the variables (bindings) are different.
And, unless data in y is
Copy, it is moved to x in the example, so you can’t use y after the
let mut x = y;. That’s the base of Rust’s memory safety guarantee.