Closed
Description
Here's my code (2.rs):
fn main() {
let x = 5;
let a = if x == 5 { 1 };
println!("{}", a);
}
On running rustc 2.rs
, I get
2.rs:3:13: 3:28 error: if may be missing an else clause [E0308]
2.rs:3 let a = if x == 5 { 1 };
^~~~~~~~~~~~~~~
2.rs:3:13: 3:28 help: run `rustc --explain E0308` to see a detailed explanation
2.rs:3:13: 3:28 note: expected type `()`
2.rs:3:13: 3:28 note: found type `_`
error: aborting due to previous error
And rustc --explain E0308
gives
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.
For example:
let x: i32 = "I am not a number!";
...
Am I missing something? Shouldn't the explanation talk about error: if may be missing an else clause
?