@@ -18,8 +18,17 @@ pub(crate) fn check<'tcx>(
18
18
left : & ' tcx Expr < ' _ > ,
19
19
right : & ' tcx Expr < ' _ > ,
20
20
) {
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)
22
29
&& is_float ( cx, left)
30
+ // Don't lint literal comparisons
31
+ && !( matches ! ( left. kind, ExprKind :: Lit ( _) ) && matches ! ( right. kind, ExprKind :: Lit ( _) ) )
23
32
// Allow comparing the results of signum()
24
33
&& !( is_signum ( cx, left) && is_signum ( cx, right) )
25
34
{
@@ -41,14 +50,7 @@ pub(crate) fn check<'tcx>(
41
50
return ;
42
51
}
43
52
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) ) {
52
54
return ;
53
55
}
54
56
@@ -106,16 +108,10 @@ fn is_allowed(val: &Constant<'_>) -> bool {
106
108
107
109
// Return true if `expr` is the result of `signum()` invoked on a float value.
108
110
fn 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
-
114
111
if let ExprKind :: MethodCall ( method_name, self_arg, ..) = expr. kind
115
112
&& 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)
118
113
{
114
+ // Check that the receiver of the signum() is a float
119
115
return is_float ( cx, self_arg) ;
120
116
}
121
117
false
0 commit comments