Example code:
fn main() {
let a = [1, 2, 3, 4, 5];
reset(a);
}
fn reset(mut b: [u32; 5]) {
b[0] = 5;
}
The variable a
is an immutable array, and the reset
function's parameter b
is a mutable array; intuitively I need to modify a
to a mutable array before I can call the reset
method, but the compiler tells me that I don't need to do this, why is this?
fn main() {
let mut a = [1, 2, 3, 4, 5];
reset(a);
}
fn reset(mut b: [u32; 5]) {
b[0] = 5;
}
warning: variable does not need to be mutable
--> src/main.rs:2:9
|
2 | let mut a = [1, 2, 3, 4, 5];
| ----^
| |
| help: remove this `mut`
|
= note: #[warn(unused_mut)] on by default