diff options
| author | Jacob Kiesel <jake@bitcrafters.co> | 2024-03-26 10:45:27 -0600 |
|---|---|---|
| committer | Jacob Kiesel <jake@bitcrafters.co> | 2024-03-26 10:45:27 -0600 |
| commit | aecdb921aed81bf3dde849e696843deddc84905e (patch) | |
| tree | 97d0866b32d4fadde393457fb41cdb4c7ba38fe9 | |
| parent | 0cf9d9c440044b07351f0d3405fc675de8885c09 (diff) | |
| download | rust-aecdb921aed81bf3dde849e696843deddc84905e.tar.gz rust-aecdb921aed81bf3dde849e696843deddc84905e.zip | |
short circuit logic better
| -rw-r--r-- | clippy_lints/src/manual_clamp.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/clippy_lints/src/manual_clamp.rs b/clippy_lints/src/manual_clamp.rs index 0148e6deb56..f484672bc3a 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 + } } } |
