@@ -364,6 +364,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
364
364
if is_allowed ( cx, left) || is_allowed ( cx, right) {
365
365
return ;
366
366
}
367
+
368
+ // Allow comparing the results of signum()
369
+ if is_signum ( cx, left) && is_signum ( cx, right) {
370
+ return ;
371
+ }
372
+
367
373
if let Some ( name) = get_item_name ( cx, expr) {
368
374
let name = name. as_str ( ) ;
369
375
if name == "eq"
@@ -493,6 +499,25 @@ fn is_allowed<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> bool {
493
499
}
494
500
}
495
501
502
+ // Return true if `expr` is the result of `signum()` invoked on a float value.
503
+ fn is_signum ( cx : & LateContext < ' _ , ' _ > , expr : & Expr ) -> bool {
504
+ // The negation of a signum is still a signum
505
+ if let ExprKind :: Unary ( UnNeg , ref child_expr) = expr. node {
506
+ return is_signum ( cx, & child_expr) ;
507
+ }
508
+
509
+ if_chain ! {
510
+ if let ExprKind :: MethodCall ( ref method_name, _, ref expressions) = expr. node;
511
+ if sym!( signum) == method_name. ident. name;
512
+ // Check that the receiver of the signum() is a float (expressions[0] is the receiver of
513
+ // the method call)
514
+ then {
515
+ return is_float( cx, & expressions[ 0 ] ) ;
516
+ }
517
+ }
518
+ false
519
+ }
520
+
496
521
fn is_float ( cx : & LateContext < ' _ , ' _ > , expr : & Expr ) -> bool {
497
522
matches ! ( walk_ptrs_ty( cx. tables. expr_ty( expr) ) . sty, ty:: Float ( _) )
498
523
}
0 commit comments