@@ -2,9 +2,10 @@ use clippy_utils::consts::{constant, Constant};
2
2
use clippy_utils:: diagnostics:: span_lint_and_then;
3
3
use clippy_utils:: sugg:: Sugg ;
4
4
use clippy_utils:: visitors:: { for_each_expr_without_closures, is_const_evaluatable} ;
5
- use clippy_utils:: { get_item_name, is_expr_named_const, peel_hir_expr_while, SpanlessEq } ;
5
+ use clippy_utils:: { get_item_name, is_expr_named_const, path_res , peel_hir_expr_while, SpanlessEq } ;
6
6
use core:: ops:: ControlFlow ;
7
7
use rustc_errors:: Applicability ;
8
+ use rustc_hir:: def:: Res ;
8
9
use rustc_hir:: { BinOpKind , BorrowKind , Expr , ExprKind , Safety , UnOp } ;
9
10
use rustc_lint:: LateContext ;
10
11
use rustc_middle:: ty:: { self , Ty , TypeFlags , TypeVisitableExt } ;
@@ -32,6 +33,10 @@ pub(crate) fn check<'tcx>(
32
33
&& !( matches ! ( left_reduced. kind, ExprKind :: Lit ( _) ) && matches ! ( right_reduced. kind, ExprKind :: Lit ( _) ) )
33
34
// Allow comparing the results of signum()
34
35
&& !( is_signum ( cx, left_reduced) && is_signum ( cx, right_reduced) )
36
+ && match ( path_res ( cx, left_reduced) , path_res ( cx, right_reduced) ) {
37
+ ( Res :: Err , _) | ( _, Res :: Err ) => true ,
38
+ ( left, right) => left != right,
39
+ }
35
40
{
36
41
let left_c = constant ( cx, cx. typeck_results ( ) , left_reduced) ;
37
42
let is_left_const = left_c. is_some ( ) ;
@@ -51,7 +56,9 @@ pub(crate) fn check<'tcx>(
51
56
return ;
52
57
}
53
58
54
- if config. ignore_named_constants && ( is_expr_named_const ( cx, left_reduced) || is_expr_named_const ( cx, right_reduced) ) {
59
+ if config. ignore_named_constants
60
+ && ( is_expr_named_const ( cx, left_reduced) || is_expr_named_const ( cx, right_reduced) )
61
+ {
55
62
return ;
56
63
}
57
64
@@ -64,7 +71,7 @@ pub(crate) fn check<'tcx>(
64
71
65
72
if let Some ( name) = get_item_name ( cx, expr) {
66
73
let name = name. as_str ( ) ;
67
- if name == "eq" || name == "ne" || name == "is_nan" || name . starts_with ( "eq_" ) || name. ends_with ( "_eq" ) {
74
+ if name == "eq" || name == "ne" || name. starts_with ( "eq_" ) || name. ends_with ( "_eq" ) {
68
75
return ;
69
76
}
70
77
}
0 commit comments