Allow the if_not_else Clippy lint

Specifically, the [`if_not_else`] lint will sometimes flag
code to change the order of `if` and `else` bodies if this
would allow a `!` to be removed. While perhaps tasteful in
some cases, there are many cases in my experience where this
bows to other competing concerns that impact readability.
(Such as the relative sizes of the `if` and `else` bodies,
or perhaps an ordering that just makes the code flow in a
more natural way.)

[`if_not_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#/if_not_else
This commit is contained in:
Andrew Gallant 2025-09-09 08:15:15 -04:00 committed by Andrew Gallant
parent 61f906d8e7
commit 25853e2377
5 changed files with 8 additions and 4 deletions

View file

@ -251,6 +251,14 @@ rest_pat_in_fully_bound_structs = "warn"
redundant_clone = "warn" redundant_clone = "warn"
debug_assert_with_mut_call = "warn" debug_assert_with_mut_call = "warn"
unused_peekable = "warn" unused_peekable = "warn"
# This lint sometimes flags code whose `if` and `else`
# bodies could be flipped when a `!` operator is removed.
# While perhaps sometimes a good idea, it is also often
# not a good idea due to other factors impacting
# readability. For example, if flipping the bodies results
# in the `if` being an order of magnitude bigger than the
# `else`, then some might consider that harder to read.
if_not_else = "allow"
# Diagnostics are not actionable: Enable once https://github.com/rust-lang/rust-clippy/issues/13774 is resolved. # Diagnostics are not actionable: Enable once https://github.com/rust-lang/rust-clippy/issues/13774 is resolved.
large_stack_arrays = "allow" large_stack_arrays = "allow"

View file

@ -79,7 +79,6 @@ impl Violation for FastApiUnusedPathParameter {
function_name, function_name,
is_positional, is_positional,
} = self; } = self;
#[expect(clippy::if_not_else)]
if !is_positional { if !is_positional {
format!( format!(
"Parameter `{arg_name}` appears in route path, but not in `{function_name}` signature" "Parameter `{arg_name}` appears in route path, but not in `{function_name}` signature"

View file

@ -141,7 +141,6 @@ impl Violation for InvalidFirstArgumentNameForClassMethod {
#[derive_message_formats] #[derive_message_formats]
// The first string below is what shows up in the documentation // The first string below is what shows up in the documentation
// in the rule table, and it is the more common case. // in the rule table, and it is the more common case.
#[expect(clippy::if_not_else)]
fn message(&self) -> String { fn message(&self) -> String {
if !self.is_new { if !self.is_new {
"First argument of a class method should be named `cls`".to_string() "First argument of a class method should be named `cls`".to_string()

View file

@ -47,7 +47,6 @@ impl Violation for UselessImportAlias {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
#[expect(clippy::if_not_else)]
if !self.required_import_conflict { if !self.required_import_conflict {
"Import alias does not rename original package".to_string() "Import alias does not rename original package".to_string()
} else { } else {

View file

@ -790,7 +790,6 @@ impl Session {
// But while this seemed to work for the project root, it // But while this seemed to work for the project root, it
// simply wouldn't result in any file notifications for changes // simply wouldn't result in any file notifications for changes
// to files outside of the project root. // to files outside of the project root.
#[allow(clippy::if_not_else)] // no! it reads better this way ---AG
let watchers = if !self.client_capabilities().supports_relative_file_watcher() { let watchers = if !self.client_capabilities().supports_relative_file_watcher() {
tracing::warn!( tracing::warn!(
"Your LSP client doesn't support file watching outside of project: \ "Your LSP client doesn't support file watching outside of project: \