Skip to content

Commit aecdb92

Browse files
committed
short circuit logic better
1 parent 0cf9d9c commit aecdb92

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

clippy_lints/src/manual_clamp.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,13 @@ impl<'tcx> ClampSuggestion<'tcx> {
114114
if max_type != min_type {
115115
return false;
116116
}
117-
let max = constant(cx, cx.typeck_results(), self.params.max);
118-
let min = constant(cx, cx.typeck_results(), self.params.min);
119-
let cmp = max
120-
.zip(min)
121-
.and_then(|(max, min)| Constant::partial_cmp(cx.tcx, max_type, &min, &max));
122-
cmp.is_some_and(|cmp| cmp != Ordering::Greater)
117+
if let Some(max) = constant(cx, cx.typeck_results(), self.params.max)
118+
&& let Some(min) = constant(cx, cx.typeck_results(), self.params.min)
119+
{
120+
Constant::partial_cmp(cx.tcx, max_type, &min, &max).is_some_and(|o| o != Ordering::Greater)
121+
} else {
122+
false
123+
}
123124
}
124125
}
125126

0 commit comments

Comments
 (0)