Answer#
Rust makes you say where a value can change, so that readers (and the compiler) know everything else cannot. Two messages cover most cases:
- E0596, "cannot borrow
xas mutable, as it is not declared as mutable": you called a method that changes the value (push,insert,clear) on a variable withoutmut. - E0384, "cannot assign twice to immutable variable": you assigned to a variable (
x = ...,x += 1) that was declared withoutmut.
The answers below show one of each.