]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0317.md
Rollup merge of #66411 - RalfJung:forget, r=sfackler
[rust.git] / src / librustc_error_codes / error_codes / E0317.md
1 This error occurs when an `if` expression without an `else` block is used in a
2 context where a type other than `()` is expected, for example a `let`
3 expression:
4
5 ```compile_fail,E0317
6 fn main() {
7     let x = 5;
8     let a = if x == 5 { 1 };
9 }
10 ```
11
12 An `if` expression without an `else` block has the type `()`, so this is a type
13 error. To resolve it, add an `else` block having the same type as the `if`
14 block.