fn foo(&mut a: u32) {
a = 3;
}
fn main() {
let mut a = 0;
foo(&mut a);
}
Gives us:
error[E0308]: mismatched types
--> src/main.rs:1:8
|
1 | fn foo(&mut a: u32) {
| ^^^^^^ expected u32, found &mut _
|
= note: expected type `u32`
found type `&mut _`
= help: did you mean `mut a: &u32`?
error[E0308]: mismatched types
--> src/main.rs:7:9
|
7 | foo(&mut a);
| ^^^^^^
| |
| expected u32, found mutable reference
| help: consider removing the borrow: `a`
|
= note: expected type `u32`
found type `&mut {integer}`
It is a little bit hard for the compiler to tell, what the user actually wants. Does he want to mutate the passed variable (a: &mut u32) or does he want to mutate the copied variable (mut a: u32). Does &mut a: u32 even makes sense at all?
What can be improved on the compiler side? Can clippy do something?