From aecdb921aed81bf3dde849e696843deddc84905e Mon Sep 17 00:00:00 2001 From: Jacob Kiesel Date: Tue, 26 Mar 2024 10:45:27 -0600 Subject: [PATCH] short circuit logic better --- clippy_lints/src/manual_clamp.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/manual_clamp.rs b/clippy_lints/src/manual_clamp.rs index 0148e6deb..f484672bc 100644 --- a/clippy_lints/src/manual_clamp.rs +++ b/clippy_lints/src/manual_clamp.rs @@ -114,12 +114,13 @@ impl<'tcx> ClampSuggestion<'tcx> { if max_type != min_type { return false; } - let max = constant(cx, cx.typeck_results(), self.params.max); - let min = constant(cx, cx.typeck_results(), self.params.min); - let cmp = max - .zip(min) - .and_then(|(max, min)| Constant::partial_cmp(cx.tcx, max_type, &min, &max)); - cmp.is_some_and(|cmp| cmp != Ordering::Greater) + if let Some(max) = constant(cx, cx.typeck_results(), self.params.max) + && let Some(min) = constant(cx, cx.typeck_results(), self.params.min) + { + Constant::partial_cmp(cx.tcx, max_type, &min, &max).is_some_and(|o| o != Ordering::Greater) + } else { + false + } } }