Skip to content

Commit aad3686

Browse files
committed
Add error markers for obfuscated_if_else lint
1 parent d79f862 commit aad3686

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

tests/ui/obfuscated_if_else.fixed

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@
33

44
fn main() {
55
if true { "a" } else { "b" };
6+
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
67
if true { "a" } else { "b" };
8+
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
79

810
let a = 1;
911
if a == 1 { "a" } else { "b" };
12+
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
1013
if a == 1 { "a" } else { "b" };
14+
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
1115

1216
let partial = (a == 1).then_some("a");
1317
partial.unwrap_or("b"); // not lint
1418

1519
let mut a = 0;
1620
if true { a += 1 } else { () };
21+
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
1722
if true { () } else { a += 2 };
23+
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
1824
}

tests/ui/obfuscated_if_else.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@
33

44
fn main() {
55
true.then_some("a").unwrap_or("b");
6+
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
67
true.then(|| "a").unwrap_or("b");
8+
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
79

810
let a = 1;
911
(a == 1).then_some("a").unwrap_or("b");
12+
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
1013
(a == 1).then(|| "a").unwrap_or("b");
14+
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
1115

1216
let partial = (a == 1).then_some("a");
1317
partial.unwrap_or("b"); // not lint
1418

1519
let mut a = 0;
1620
true.then_some(a += 1).unwrap_or(());
21+
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
1722
true.then_some(()).unwrap_or(a += 2);
23+
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
1824
}

tests/ui/obfuscated_if_else.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@ LL | true.then_some("a").unwrap_or("b");
88
= help: to override `-D warnings` add `#[allow(clippy::obfuscated_if_else)]`
99

1010
error: this method chain can be written more clearly with `if .. else ..`
11-
--> tests/ui/obfuscated_if_else.rs:6:5
11+
--> tests/ui/obfuscated_if_else.rs:7:5
1212
|
1313
LL | true.then(|| "a").unwrap_or("b");
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { "a" } else { "b" }`
1515

1616
error: this method chain can be written more clearly with `if .. else ..`
17-
--> tests/ui/obfuscated_if_else.rs:9:5
17+
--> tests/ui/obfuscated_if_else.rs:11:5
1818
|
1919
LL | (a == 1).then_some("a").unwrap_or("b");
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if a == 1 { "a" } else { "b" }`
2121

2222
error: this method chain can be written more clearly with `if .. else ..`
23-
--> tests/ui/obfuscated_if_else.rs:10:5
23+
--> tests/ui/obfuscated_if_else.rs:13:5
2424
|
2525
LL | (a == 1).then(|| "a").unwrap_or("b");
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if a == 1 { "a" } else { "b" }`
2727

2828
error: this method chain can be written more clearly with `if .. else ..`
29-
--> tests/ui/obfuscated_if_else.rs:16:5
29+
--> tests/ui/obfuscated_if_else.rs:20:5
3030
|
3131
LL | true.then_some(a += 1).unwrap_or(());
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { a += 1 } else { () }`
3333

3434
error: this method chain can be written more clearly with `if .. else ..`
35-
--> tests/ui/obfuscated_if_else.rs:17:5
35+
--> tests/ui/obfuscated_if_else.rs:22:5
3636
|
3737
LL | true.then_some(()).unwrap_or(a += 2);
3838
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `if true { () } else { a += 2 }`

0 commit comments

Comments
 (0)