Why can immutable variables be passed as arguments to functions that require mutable arguments?
问题 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 -->