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
Also the explanation says:
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 the most common case passing the wrong type to a function? Usually people do not provide a type annotation to a let unless it is necessary to help the compiler figure out what concrete type a generic is. Perhaps the explanation could be clarified and expanded upon for that.
@jyn514 You beat me to it :)
let x: i32 = "I am not a number!"; // ~~~ ~~~~~~~~~~~~~~~~~~~~ // | | // | initializing expression; // | compiler infers type `&str` // | // type `i32` assigned to variable `x`
Also, the diagnostics shown in the code example seem out of date.
Mentoring instructions:
Change compiler/rustc_error_codes/src/error_codes/E0308.md to have an up-to-date diagnostic and appropriate long description.
On it.
Proposed text:
Expected type did not match the received type.
Erroneous code example:
```compile_fail,E0308
fn plus_one(x: i32) -> i32 {
x + 1
}plus_one("Not a number");
// ^^^^^^^^^^^^^^ expectedi32, found&strif "Not a bool" {
// ^^^^^^^^^^^^ expectedbool, found&str
}
```This error occurs when an expression was used in a place where the compiler
expected an expression of a different type. It can occur in several cases, the
most common being when calling a function, and passing an argument which has a
different type than the matching argument in the function declaration.
Overall text looks good. Can you open a PR and @-mention me on it?