Add error markers for obfuscated_if_else lint

This commit is contained in:
Samuel Tardieu 2025-02-09 01:53:19 +01:00
parent d79f86255d
commit aad3686823
3 changed files with 17 additions and 5 deletions

View file

@ -3,16 +3,22 @@
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 ..`
}