]> git.lizzy.rs Git - rust.git/blob - src/docs/unit_cmp.txt
Add iter_kv_map lint
[rust.git] / src / docs / unit_cmp.txt
1 ### What it does
2 Checks for comparisons to unit. This includes all binary
3 comparisons (like `==` and `<`) and asserts.
4
5 ### Why is this bad?
6 Unit is always equal to itself, and thus is just a
7 clumsily written constant. Mostly this happens when someone accidentally
8 adds semicolons at the end of the operands.
9
10 ### Example
11 ```
12 if {
13     foo();
14 } == {
15     bar();
16 } {
17     baz();
18 }
19 ```
20 is equal to
21 ```
22 {
23     foo();
24     bar();
25     baz();
26 }
27 ```
28
29 For asserts:
30 ```
31 assert_eq!({ foo(); }, { bar(); });
32 ```
33 will always succeed