]> git.lizzy.rs Git - rust.git/blob - src/docs/else_if_without_else.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / else_if_without_else.txt
1 ### What it does
2 Checks for usage of if expressions with an `else if` branch,
3 but without a final `else` branch.
4
5 ### Why is this bad?
6 Some coding guidelines require this (e.g., MISRA-C:2004 Rule 14.10).
7
8 ### Example
9 ```
10 if x.is_positive() {
11     a();
12 } else if x.is_negative() {
13     b();
14 }
15 ```
16
17 Use instead:
18
19 ```
20 if x.is_positive() {
21     a();
22 } else if x.is_negative() {
23     b();
24 } else {
25     // We don't care about zero.
26 }
27 ```