]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0308.md
Update description for error E0308
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0308.md
1 Expected type did not match the received type.
2
3 Erroneous code examples:
4
5 ```compile_fail,E0308
6 fn plus_one(x: i32) -> i32 {
7     x + 1
8 }
9
10 plus_one("Not a number");
11 //       ^^^^^^^^^^^^^^ expected `i32`, found `&str`
12
13 if "Not a bool" {
14 // ^^^^^^^^^^^^ expected `bool`, found `&str`
15 }
16
17 let x: f32 = "Not a float";
18 //     ---   ^^^^^^^^^^^^^ expected `f32`, found `&str`
19 //     |
20 //     expected due to this
21 ```
22
23 This error occurs when an expression was used in a place where the compiler
24 expected an expression of a different type. It can occur in several cases, the
25 most common being when calling a function and passing an argument which has a
26 different type than the matching type in the function declaration.