Add error markers for obfuscated_if_else lint
This commit is contained in:
parent
d79f86255d
commit
aad3686823
3 changed files with 17 additions and 5 deletions
|
|
@ -3,16 +3,22 @@
|
|||
|
||||
fn main() {
|
||||
true.then_some("a").unwrap_or("b");
|
||||
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
|
||||
true.then(|| "a").unwrap_or("b");
|
||||
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
|
||||
|
||||
let a = 1;
|
||||
(a == 1).then_some("a").unwrap_or("b");
|
||||
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
|
||||
(a == 1).then(|| "a").unwrap_or("b");
|
||||
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
|
||||
|
||||
let partial = (a == 1).then_some("a");
|
||||
partial.unwrap_or("b"); // not lint
|
||||
|
||||
let mut a = 0;
|
||||
true.then_some(a += 1).unwrap_or(());
|
||||
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
|
||||
true.then_some(()).unwrap_or(a += 2);
|
||||
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue