36 ms·
It doesn't have the same semantics, because even after introducing the new variable, it is still immutable. So you cannot accidentally modify the new variable.
by yokohummer7 10y ago
It doesn't have the same semantics, because even after introducing the new variable, it is still immutable. So you cannot accidentally modify the new variable. e.g.,
let x = 1;
let x = x + 1;
x = 99; // Error: you can't accidentally modify the immutable variable `x`
let mut x = 1;
x = x + 1;
x = 99; // Ok
You can even turn back a mutable varaible into an immutable variable, like this:
let mut x = 1;
x = x + 1;
let x = x;
x = 99; // Error: `x` became immutable
This can be useful to "pin" the variable after a large number of calculations done to it.