@@ -2,7 +2,7 @@ use crate::consts::{
22 constant, constant_simple, Constant ,
33 Constant :: { Int , F32 , F64 } ,
44} ;
5- use crate :: utils:: { get_parent_expr, higher, numeric_literal, span_lint_and_sugg, sugg, SpanlessEq } ;
5+ use crate :: utils:: { eq_expr_value , get_parent_expr, higher, numeric_literal, span_lint_and_sugg, sugg} ;
66use if_chain:: if_chain;
77use rustc_errors:: Applicability ;
88use rustc_hir:: { BinOpKind , Expr , ExprKind , PathSegment , UnOp } ;
@@ -363,8 +363,8 @@ fn detect_hypot(cx: &LateContext<'_>, args: &[Expr<'_>]) -> Option<String> {
363363 if_chain ! {
364364 if let ExprKind :: Binary ( Spanned { node: BinOpKind :: Mul , .. } , ref lmul_lhs, ref lmul_rhs) = add_lhs. kind;
365365 if let ExprKind :: Binary ( Spanned { node: BinOpKind :: Mul , .. } , ref rmul_lhs, ref rmul_rhs) = add_rhs. kind;
366- if are_exprs_equal ( cx, lmul_lhs, lmul_rhs) ;
367- if are_exprs_equal ( cx, rmul_lhs, rmul_rhs) ;
366+ if eq_expr_value ( cx, lmul_lhs, lmul_rhs) ;
367+ if eq_expr_value ( cx, rmul_lhs, rmul_rhs) ;
368368 then {
369369 return Some ( format!( "{}.hypot({})" , Sugg :: hir( cx, & lmul_lhs, ".." ) , Sugg :: hir( cx, & rmul_lhs, ".." ) ) ) ;
370370 }
@@ -502,8 +502,8 @@ fn check_mul_add(cx: &LateContext<'_>, expr: &Expr<'_>) {
502502fn is_testing_positive ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > , test : & Expr < ' _ > ) -> bool {
503503 if let ExprKind :: Binary ( Spanned { node : op, .. } , left, right) = expr. kind {
504504 match op {
505- BinOpKind :: Gt | BinOpKind :: Ge => is_zero ( cx, right) && are_exprs_equal ( cx, left, test) ,
506- BinOpKind :: Lt | BinOpKind :: Le => is_zero ( cx, left) && are_exprs_equal ( cx, right, test) ,
505+ BinOpKind :: Gt | BinOpKind :: Ge => is_zero ( cx, right) && eq_expr_value ( cx, left, test) ,
506+ BinOpKind :: Lt | BinOpKind :: Le => is_zero ( cx, left) && eq_expr_value ( cx, right, test) ,
507507 _ => false ,
508508 }
509509 } else {
@@ -515,19 +515,15 @@ fn is_testing_positive(cx: &LateContext<'_>, expr: &Expr<'_>, test: &Expr<'_>) -
515515fn is_testing_negative ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > , test : & Expr < ' _ > ) -> bool {
516516 if let ExprKind :: Binary ( Spanned { node : op, .. } , left, right) = expr. kind {
517517 match op {
518- BinOpKind :: Gt | BinOpKind :: Ge => is_zero ( cx, left) && are_exprs_equal ( cx, right, test) ,
519- BinOpKind :: Lt | BinOpKind :: Le => is_zero ( cx, right) && are_exprs_equal ( cx, left, test) ,
518+ BinOpKind :: Gt | BinOpKind :: Ge => is_zero ( cx, left) && eq_expr_value ( cx, right, test) ,
519+ BinOpKind :: Lt | BinOpKind :: Le => is_zero ( cx, right) && eq_expr_value ( cx, left, test) ,
520520 _ => false ,
521521 }
522522 } else {
523523 false
524524 }
525525}
526526
527- fn are_exprs_equal ( cx : & LateContext < ' _ > , expr1 : & Expr < ' _ > , expr2 : & Expr < ' _ > ) -> bool {
528- SpanlessEq :: new ( cx) . ignore_fn ( ) . eq_expr ( expr1, expr2)
529- }
530-
531527/// Returns true iff expr is some zero literal
532528fn is_zero ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
533529 match constant_simple ( cx, cx. typeck_results ( ) , expr) {
@@ -546,12 +542,12 @@ fn is_zero(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
546542/// returns None.
547543fn are_negated < ' a > ( cx : & LateContext < ' _ > , expr1 : & ' a Expr < ' a > , expr2 : & ' a Expr < ' a > ) -> Option < ( bool , & ' a Expr < ' a > ) > {
548544 if let ExprKind :: Unary ( UnOp :: UnNeg , expr1_negated) = & expr1. kind {
549- if are_exprs_equal ( cx, expr1_negated, expr2) {
545+ if eq_expr_value ( cx, expr1_negated, expr2) {
550546 return Some ( ( false , expr2) ) ;
551547 }
552548 }
553549 if let ExprKind :: Unary ( UnOp :: UnNeg , expr2_negated) = & expr2. kind {
554- if are_exprs_equal ( cx, expr1, expr2_negated) {
550+ if eq_expr_value ( cx, expr1, expr2_negated) {
555551 return Some ( ( true , expr1) ) ;
556552 }
557553 }
@@ -614,7 +610,7 @@ fn are_same_base_logs(cx: &LateContext<'_>, expr_a: &Expr<'_>, expr_b: &Expr<'_>
614610 args_a. len( ) == args_b. len( ) &&
615611 (
616612 [ "ln" , "log2" , "log10" ] . contains( &&* method_name_a. as_str( ) ) ||
617- method_name_a. as_str( ) == "log" && args_a. len( ) == 2 && are_exprs_equal ( cx, & args_a[ 1 ] , & args_b[ 1 ] )
613+ method_name_a. as_str( ) == "log" && args_a. len( ) == 2 && eq_expr_value ( cx, & args_a[ 1 ] , & args_b[ 1 ] )
618614 ) ;
619615 }
620616 }
0 commit comments