Skip to content

Commit 37c7fab

Browse files
committed
simplify call_max_min even further
1 parent b4cbbd5 commit 37c7fab

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

clippy_lints/src/manual_clamp.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -305,23 +305,14 @@ fn is_call_max_min_pattern<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>)
305305
OrdOrFloat(&'tcx PathSegment<'tcx>),
306306
}
307307

308-
fn extract_call_data(e: ExprRef<'_>, is_first: bool) -> Option<(ExprRef<'_>, ExprRef<'_>, ExprRef<'_>, bool)> {
309-
if let ExprKind::Call(inner_fn, &[ref third, ref fourth]) = &e.kind {
310-
Some((inner_fn, third, fourth, is_first))
311-
} else {
312-
None
313-
}
314-
}
315-
316308
fn check<'tcx>(
317309
cx: &LateContext<'tcx>,
318310
outer_fn: ExprRef<'tcx>,
319311
first: ExprRef<'tcx>,
320312
second: ExprRef<'tcx>,
321313
span: Span,
322314
) -> Option<ClampSuggestion<'tcx>> {
323-
if let Ok((inner_fn, third, fourth, is_first)) =
324-
extract_call_data(first, true).into_iter().chain(extract_call_data(second, false)).exactly_one()
315+
if let ExprKind::Call(inner_fn, &[ref third, ref fourth]) = &first.kind
325316
&& let Some(inner_seg) = segment(cx, inner_fn)
326317
&& let Some(outer_seg) = segment(cx, outer_fn) {
327318
let third_is_const = constant(cx, cx.typeck_results(), simplify_kind(third)).is_some();
@@ -333,11 +324,7 @@ fn is_call_max_min_pattern<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>)
333324
(false, true) => (input, new_arg) = (third, fourth),
334325
_ => return None,
335326
}
336-
let other_new_arg = if is_first {
337-
second
338-
} else {
339-
first
340-
};
327+
let other_new_arg = second;
341328
let is_float = cx.typeck_results().expr_ty_adjusted(input).is_floating_point();
342329
let min_max_suggestion = Some(ClampSuggestion {
343330
params: InputMinMax { input, min: other_new_arg, max: new_arg, is_float },

0 commit comments

Comments
 (0)