@@ -82,29 +82,26 @@ impl Variant {
8282
8383impl < ' tcx > LateLintPass < ' tcx > for ManualFloatMethods {
8484 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > ) {
85- if !in_external_macro ( cx. sess ( ) , expr. span )
86- && (
87- matches ! ( cx. tcx. constness( cx. tcx. hir( ) . enclosing_body_owner( expr. hir_id) ) , Constness :: NotConst )
88- || cx. tcx . features ( ) . declared ( sym ! ( const_float_classify) )
89- ) && let ExprKind :: Binary ( kind, lhs, rhs) = expr. kind
85+ if let ExprKind :: Binary ( kind, lhs, rhs) = expr. kind
9086 && let ExprKind :: Binary ( lhs_kind, lhs_lhs, lhs_rhs) = lhs. kind
9187 && let ExprKind :: Binary ( rhs_kind, rhs_lhs, rhs_rhs) = rhs. kind
9288 // Checking all possible scenarios using a function would be a hopeless task, as we have
9389 // 16 possible alignments of constants/operands. For now, let's use `partition`.
94- && let ( operands, constants) = [ lhs_lhs, lhs_rhs, rhs_lhs, rhs_rhs]
95- . into_iter ( )
96- . partition :: < Vec < & Expr < ' _ > > , _ > ( |i| path_to_local ( i) . is_some ( ) )
97- && let [ first, second] = & * operands
98- && let Some ( [ const_1, const_2] ) = constants
99- . into_iter ( )
100- . map ( |i| constant ( cx, cx. typeck_results ( ) , i) )
101- . collect :: < Option < Vec < _ > > > ( )
102- . as_deref ( )
90+ && let mut exprs = [ lhs_lhs, lhs_rhs, rhs_lhs, rhs_rhs]
91+ && exprs. iter_mut ( ) . partition_in_place ( |i| path_to_local ( i) . is_some ( ) ) == 2
92+ && !in_external_macro ( cx. sess ( ) , expr. span )
93+ && (
94+ matches ! ( cx. tcx. constness( cx. tcx. hir( ) . enclosing_body_owner( expr. hir_id) ) , Constness :: NotConst )
95+ || cx. tcx . features ( ) . declared ( sym ! ( const_float_classify) )
96+ )
97+ && let [ first, second, const_1, const_2] = exprs
98+ && let Some ( const_1) = constant ( cx, cx. typeck_results ( ) , const_1)
99+ && let Some ( const_2) = constant ( cx, cx. typeck_results ( ) , const_2)
103100 && path_to_local ( first) . is_some_and ( |f| path_to_local ( second) . is_some_and ( |s| f == s) )
104101 // The actual infinity check, we also allow `NEG_INFINITY` before` INFINITY` just in
105102 // case somebody does that for some reason
106- && ( is_infinity ( const_1) && is_neg_infinity ( const_2)
107- || is_neg_infinity ( const_1) && is_infinity ( const_2) )
103+ && ( is_infinity ( & const_1) && is_neg_infinity ( & const_2)
104+ || is_neg_infinity ( & const_1) && is_infinity ( & const_2) )
108105 && let Some ( local_snippet) = snippet_opt ( cx, first. span )
109106 {
110107 let variant = match ( kind. node , lhs_kind. node , rhs_kind. node ) {
0 commit comments