]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/src/docs/same_functions_in_if_condition.txt
New upstream version 1.66.0+dfsg1
[rustc.git] / src / tools / clippy / src / docs / same_functions_in_if_condition.txt
CommitLineData
f2b60f7d
FG
1### What it does
2Checks for consecutive `if`s with the same function call.
3
4### Why is this bad?
5This is probably a copy & paste error.
6Despite the fact that function can have side effects and `if` works as
7intended, such an approach is implicit and can be considered a "code smell".
8
9### Example
10```
11if foo() == bar {
12
13} else if foo() == bar {
14
15}
16```
17
18This probably should be:
19```
20if foo() == bar {
21
22} else if foo() == baz {
23
24}
25```
26
27or if the original code was not a typo and called function mutates a state,
28consider move the mutation out of the `if` condition to avoid similarity to
29a copy & paste error:
30
31```
32let first = foo();
33if first == bar {
34
35} else {
36 let second = foo();
37 if second == bar {
38
39 }
40}
41```