2022-07-10 14:37:38 -07:00
|
|
|
#![warn(clippy::obfuscated_if_else)]
|
2025-01-22 18:57:20 +09:00
|
|
|
#![allow(clippy::unnecessary_lazy_evaluations, clippy::unit_arg, clippy::unused_unit)]
|
2022-07-10 14:37:38 -07:00
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
if true { "a" } else { "b" };
|
2025-02-09 01:53:19 +01:00
|
|
|
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
|
2025-01-18 18:06:04 +09:00
|
|
|
if true { "a" } else { "b" };
|
2025-02-09 01:53:19 +01:00
|
|
|
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
|
2025-01-18 18:06:04 +09:00
|
|
|
|
|
|
|
|
let a = 1;
|
|
|
|
|
if a == 1 { "a" } else { "b" };
|
2025-02-09 01:53:19 +01:00
|
|
|
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
|
2025-01-18 18:06:04 +09:00
|
|
|
if a == 1 { "a" } else { "b" };
|
2025-02-09 01:53:19 +01:00
|
|
|
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
|
2025-01-18 18:06:04 +09:00
|
|
|
|
|
|
|
|
let partial = (a == 1).then_some("a");
|
|
|
|
|
partial.unwrap_or("b"); // not lint
|
2025-01-22 18:57:20 +09:00
|
|
|
|
|
|
|
|
let mut a = 0;
|
|
|
|
|
if true { a += 1 } else { () };
|
2025-02-09 01:53:19 +01:00
|
|
|
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
|
2025-01-22 18:57:20 +09:00
|
|
|
if true { () } else { a += 2 };
|
2025-02-09 01:53:19 +01:00
|
|
|
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
|
2022-07-10 14:37:38 -07:00
|
|
|
}
|