Skip to content

Latest commit

 

History

History
19 lines (16 loc) · 631 Bytes

File metadata and controls

19 lines (16 loc) · 631 Bytes

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 was unable to infer the concrete type of a variable. It can occur for several cases, the most common of which is a mismatch in the expected type that the compiler inferred for a variable's initializing expression, and the actual type explicitly assigned to the variable.