@@ -18,8 +18,17 @@ pub(crate) fn check<'tcx>(
1818 left : & ' tcx Expr < ' _ > ,
1919 right : & ' tcx Expr < ' _ > ,
2020) {
21- if ( op == BinOpKind :: Eq || op == BinOpKind :: Ne )
21+ let peel_expr = |e : & ' tcx Expr < ' tcx > | match e. kind {
22+ ExprKind :: Cast ( e, _) | ExprKind :: AddrOf ( BorrowKind :: Ref , _, e) | ExprKind :: Unary ( UnOp :: Neg , e) => Some ( e) ,
23+ _ => None ,
24+ } ;
25+
26+ if matches ! ( op, BinOpKind :: Eq | BinOpKind :: Ne )
27+ && let left = peel_hir_expr_while ( left, peel_expr)
28+ && let right = peel_hir_expr_while ( right, peel_expr)
2229 && is_float ( cx, left)
30+ // Don't lint literal comparisons
31+ && !( matches ! ( left. kind, ExprKind :: Lit ( _) ) && matches ! ( right. kind, ExprKind :: Lit ( _) ) )
2332 // Allow comparing the results of signum()
2433 && !( is_signum ( cx, left) && is_signum ( cx, right) )
2534 {
@@ -41,14 +50,7 @@ pub(crate) fn check<'tcx>(
4150 return ;
4251 }
4352
44- let peel_expr = |e : & ' tcx Expr < ' tcx > | match e. kind {
45- ExprKind :: Cast ( e, _) | ExprKind :: AddrOf ( BorrowKind :: Ref , _, e) => Some ( e) ,
46- _ => None ,
47- } ;
48- if config. ignore_named_constants
49- && ( is_expr_named_const ( cx, peel_hir_expr_while ( left, peel_expr) )
50- || is_expr_named_const ( cx, peel_hir_expr_while ( right, peel_expr) ) )
51- {
53+ if config. ignore_named_constants && ( is_expr_named_const ( cx, left) || is_expr_named_const ( cx, right) ) {
5254 return ;
5355 }
5456
@@ -106,16 +108,10 @@ fn is_allowed(val: &Constant<'_>) -> bool {
106108
107109// Return true if `expr` is the result of `signum()` invoked on a float value.
108110fn is_signum ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
109- // The negation of a signum is still a signum
110- if let ExprKind :: Unary ( UnOp :: Neg , child_expr) = expr. kind {
111- return is_signum ( cx, child_expr) ;
112- }
113-
114111 if let ExprKind :: MethodCall ( method_name, self_arg, ..) = expr. kind
115112 && sym ! ( signum) == method_name. ident . name
116- // Check that the receiver of the signum() is a float (expressions[0] is the receiver of
117- // the method call)
118113 {
114+ // Check that the receiver of the signum() is a float
119115 return is_float ( cx, self_arg) ;
120116 }
121117 false
0 commit comments