-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change the applicability of
obfuscated_if_else
depending on whether…
… the original code can have side effects
- Loading branch information
1 parent
396de57
commit add9f0a
Showing
4 changed files
with
31 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
#![warn(clippy::obfuscated_if_else)] | ||
#![allow(clippy::unit_arg, clippy::unused_unit)] | ||
|
||
fn main() { | ||
if true { "a" } else { "b" }; | ||
|
||
let mut a = 0; | ||
if true { a += 1 } else { () }; | ||
if true { () } else { a += 2 }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
#![warn(clippy::obfuscated_if_else)] | ||
#![allow(clippy::unit_arg, clippy::unused_unit)] | ||
|
||
fn main() { | ||
true.then_some("a").unwrap_or("b"); | ||
|
||
let mut a = 0; | ||
true.then_some(a += 1).unwrap_or(()); | ||
true.then_some(()).unwrap_or(a += 2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
error: use of `.then_some(..).unwrap_or(..)` can be written more clearly with `if .. else ..` | ||
--> tests/ui/obfuscated_if_else.rs:4:5 | ||
--> tests/ui/obfuscated_if_else.rs:5:5 | ||
| | ||
LL | true.then_some("a").unwrap_or("b"); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { "a" } else { "b" }` | ||
| | ||
= note: `-D clippy::obfuscated-if-else` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::obfuscated_if_else)]` | ||
|
||
error: aborting due to 1 previous error | ||
error: use of `.then_some(..).unwrap_or(..)` can be written more clearly with `if .. else ..` | ||
--> tests/ui/obfuscated_if_else.rs:8:5 | ||
| | ||
LL | true.then_some(a += 1).unwrap_or(()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { a += 1 } else { () }` | ||
|
||
error: use of `.then_some(..).unwrap_or(..)` can be written more clearly with `if .. else ..` | ||
--> tests/ui/obfuscated_if_else.rs:9:5 | ||
| | ||
LL | true.then_some(()).unwrap_or(a += 2); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { () } else { a += 2 }` | ||
|
||
error: aborting due to 3 previous errors | ||
|