From 7d2abd0549abb3bad56a5a7dbeb504cffadfb948 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Tue, 26 Nov 2024 14:57:26 -0500 Subject: [PATCH] clippy: allow `if_not_else` This lint fires when an `if` negates the condition. The lint instead suggests that the condition should be un-negated and the `if` and `else` bodies flipped. I find this to be a pretty annoying lint, because sometimes I want to keep the order of the `if` and `else` bodies as-is, and not make it subject to whether the primary condition is negated or not. Sometimes it's for linear scanning reasons (where the `if` block is smaller), and sometimes it's for "code parallelism" reasons (i.e., this block of code looks like another block of code intentionally). Moreover, I don't think the benefits of this lint are very big. I do agree that sometimes negating a conditional can make it harder to read (e.g., a double negative), but it's nowhere near a universal truth enough to ban it outright. --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 664cdd9ad..c6c9af9e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -222,6 +222,7 @@ get_unwrap = "warn" rc_buffer = "warn" rc_mutex = "warn" rest_pat_in_fully_bound_structs = "warn" +if_not_else = "allow" [profile.release] strip = true