about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2025-04-09 09:56:56 +0200
committerSamuel Tardieu <sam@rfc1149.net>2025-04-09 10:47:41 +0200
commita7280e0374a8249b53f1fce25c2a4cb886d58fa2 (patch)
tree8230d11945392200c970b7195568f2800811c9c6
parent97bb0639585096faa050b80a289836e46ddc3210 (diff)
Use explicit `return` instead of empty block to bail out from lint
No change in functionality.
-rw-r--r--clippy_lints/src/non_canonical_impls.rs87
1 files changed, 44 insertions, 43 deletions
diff --git a/clippy_lints/src/non_canonical_impls.rs b/clippy_lints/src/non_canonical_impls.rs
index 448bb603cf2..329415e2dc9 100644
--- a/clippy_lints/src/non_canonical_impls.rs
+++ b/clippy_lints/src/non_canonical_impls.rs
@@ -187,6 +187,7 @@ impl LateLintPass<'_> for NonCanonicalImpls {
                 && let Some(expr) = block.expr
                 && expr_is_cmp(cx, &expr.kind, impl_item, &mut needs_fully_qualified)
             {
+                return;
             }
             // Fix #12683, allow [`needless_return`] here
             else if block.expr.is_none()
@@ -197,53 +198,53 @@ impl LateLintPass<'_> for NonCanonicalImpls {
                 }) = stmt.kind
                 && expr_is_cmp(cx, ret_kind, impl_item, &mut needs_fully_qualified)
             {
-            } else {
-                // If `Self` and `Rhs` are not the same type, bail. This makes creating a valid
-                // suggestion tons more complex.
-                if let [lhs, rhs, ..] = trait_impl.args.as_slice()
-                    && lhs != rhs
-                {
-                    return;
-                }
+                return;
+            }
+            // If `Self` and `Rhs` are not the same type, bail. This makes creating a valid
+            // suggestion tons more complex.
+            else if let [lhs, rhs, ..] = trait_impl.args.as_slice()
+                && lhs != rhs
+            {
+                return;
+            }
 
-                span_lint_and_then(
-                    cx,
-                    NON_CANONICAL_PARTIAL_ORD_IMPL,
-                    item.span,
-                    "non-canonical implementation of `partial_cmp` on an `Ord` type",
-                    |diag| {
-                        let [_, other] = body.params else {
-                            return;
-                        };
-                        let Some(std_or_core) = std_or_core(cx) else {
-                            return;
-                        };
+            span_lint_and_then(
+                cx,
+                NON_CANONICAL_PARTIAL_ORD_IMPL,
+                item.span,
+                "non-canonical implementation of `partial_cmp` on an `Ord` type",
+                |diag| {
+                    let [_, other] = body.params else {
+                        return;
+                    };
+                    let Some(std_or_core) = std_or_core(cx) else {
+                        return;
+                    };
 
-                        let suggs = match (other.pat.simple_ident(), needs_fully_qualified) {
-                            (Some(other_ident), true) => vec![(
+                    let suggs = match (other.pat.simple_ident(), needs_fully_qualified) {
+                        (Some(other_ident), true) => vec![(
+                            block.span,
+                            format!("{{ Some({std_or_core}::cmp::Ord::cmp(self, {})) }}", other_ident.name),
+                        )],
+                        (Some(other_ident), false) => {
+                            vec![(block.span, format!("{{ Some(self.cmp({})) }}", other_ident.name))]
+                        },
+                        (None, true) => vec![
+                            (
                                 block.span,
-                                format!("{{ Some({std_or_core}::cmp::Ord::cmp(self, {})) }}", other_ident.name),
-                            )],
-                            (Some(other_ident), false) => {
-                                vec![(block.span, format!("{{ Some(self.cmp({})) }}", other_ident.name))]
-                            },
-                            (None, true) => vec![
-                                (
-                                    block.span,
-                                    format!("{{ Some({std_or_core}::cmp::Ord::cmp(self, other)) }}"),
-                                ),
-                                (other.pat.span, "other".to_owned()),
-                            ],
-                            (None, false) => vec![
-                                (block.span, "{ Some(self.cmp(other)) }".to_owned()),
-                                (other.pat.span, "other".to_owned()),
-                            ],
-                        };
+                                format!("{{ Some({std_or_core}::cmp::Ord::cmp(self, other)) }}"),
+                            ),
+                            (other.pat.span, "other".to_owned()),
+                        ],
+                        (None, false) => vec![
+                            (block.span, "{ Some(self.cmp(other)) }".to_owned()),
+                            (other.pat.span, "other".to_owned()),
+                        ],
+                    };
 
-                        diag.multipart_suggestion("change this to", suggs, Applicability::Unspecified);
-                    },
-                );
-            }
+                    diag.multipart_suggestion("change this to", suggs, Applicability::Unspecified);
+                },
+            );
         }
     }
 }