Closed
Description
The following code:
fn foo(x: f64) {}
fn main() {
foo(10);
}
Produces the following error message:
error[E0308]: mismatched types
--> src/main.rs:4:9
|
4 | foo(10);
| ^^ expected f64, found integral variable
|
= note: expected type `f64`
found type `{integer}`
This error message tells you that the types are mismatched, but doesn't fully explain why. To fix it, you need to use a floating point literal instead of an integer literal. This isn't clear from the error message.
If you're new to programming or if you come from a language that doesn't draw the same distinction between integer and floating point literals, it may not be clear why the literal 10
is not the same as 10.0
.
It would be great if we could add something in our error message that would suggest one or more of the valid ways to fix this:
10.0
10.
10f64
- type could bef32
in another context