]> git.proxmox.com Git - rustc.git/blame - src/librustc_error_codes/error_codes/E0317.md
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0317.md
CommitLineData
74b04a01
XL
1An `if` expression is missing an `else` block.
2
3Erroneous code example:
60c5eb7d
XL
4
5```compile_fail,E0317
74b04a01
XL
6let x = 5;
7let a = if x == 5 {
8 1
9};
60c5eb7d
XL
10```
11
74b04a01
XL
12This error occurs when an `if` expression without an `else` block is used in a
13context where a type other than `()` is expected. In the previous code example,
14the `let` expression was expecting a value but since there was no `else`, no
15value was returned.
16
60c5eb7d
XL
17An `if` expression without an `else` block has the type `()`, so this is a type
18error. To resolve it, add an `else` block having the same type as the `if`
19block.
74b04a01
XL
20
21So to fix the previous code example:
22
23```
24let x = 5;
25let a = if x == 5 {
26 1
27} else {
28 2
29};
30```