Description
I believe the error message for E0308 is incorrect. Here it is, with my emphasis on the part that seems incorrect:
Expected type did not match the received type.
Erroneous code example:
let x: i32 = "I am not a number!"; // ~~~ ~~~~~~~~~~~~~~~~~~~~ // | | // | initializing expression; // | compiler infers type `&str` // | // type `i32` assigned to variable `x`
This error occurs when the compiler is unable to infer the concrete type of a
variable. It can occur in several cases, the most common being a mismatch
between two types: the type the author explicitly assigned, and the type the
compiler inferred.
Isn't this error because the compiler was able to infer the type, but it was not what was expected? For example, in the example provided in the error explanation, the value assigned to x
is most definitely &str
, and i32
is expected, so the types don't match.
@rustbot modify labels: A-diagnostics D-incorrect D-confusing C-bug