Files
rust/tests/ui/obfuscated_if_else.fixed

25 lines
969 B
Rust
Raw Normal View History

#![warn(clippy::obfuscated_if_else)]
#![allow(clippy::unnecessary_lazy_evaluations, clippy::unit_arg, clippy::unused_unit)]
fn main() {
if true { "a" } else { "b" };
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
if true { "a" } else { "b" };
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
let a = 1;
if a == 1 { "a" } else { "b" };
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
if a == 1 { "a" } else { "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;
if true { a += 1 } else { () };
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
if true { () } else { a += 2 };
//~^ ERROR: this method chain can be written more clearly with `if .. else ..`
}