]> git.lizzy.rs Git - rust.git/blob - src/docs/needless_bool.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / needless_bool.txt
1 ### What it does
2 Checks for expressions of the form `if c { true } else {
3 false }` (or vice versa) and suggests using the condition directly.
4
5 ### Why is this bad?
6 Redundant code.
7
8 ### Known problems
9 Maybe false positives: Sometimes, the two branches are
10 painstakingly documented (which we, of course, do not detect), so they *may*
11 have some value. Even then, the documentation can be rewritten to match the
12 shorter code.
13
14 ### Example
15 ```
16 if x {
17     false
18 } else {
19     true
20 }
21 ```
22
23 Use instead:
24 ```
25 !x
26 ```