1
1
use clippy_utils:: diagnostics:: { multispan_sugg, span_lint, span_lint_and_then} ;
2
2
use clippy_utils:: source:: snippet;
3
3
use clippy_utils:: ty:: { implements_trait, is_copy} ;
4
- use clippy_utils:: { ast_utils:: is_useless_with_eq_exprs, eq_expr_value, higher, in_macro, is_expn_of} ;
4
+ use clippy_utils:: { ast_utils:: is_useless_with_eq_exprs, eq_expr_value, higher, in_macro, is_expn_of, is_in_test_function } ;
5
5
use if_chain:: if_chain;
6
6
use rustc_errors:: Applicability ;
7
7
use rustc_hir:: { BinOpKind , BorrowKind , Expr , ExprKind , StmtKind } ;
@@ -72,23 +72,25 @@ impl<'tcx> LateLintPass<'tcx> for EqOp {
72
72
#[ allow( clippy:: similar_names, clippy:: too_many_lines) ]
73
73
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , e : & ' tcx Expr < ' _ > ) {
74
74
if let ExprKind :: Block ( block, _) = e. kind {
75
- for stmt in block. stmts {
76
- for amn in & ASSERT_MACRO_NAMES {
77
- if_chain ! {
78
- if is_expn_of( stmt. span, amn) . is_some( ) ;
79
- if let StmtKind :: Semi ( matchexpr) = stmt. kind;
80
- if let Some ( macro_args) = higher:: extract_assert_macro_args( matchexpr) ;
81
- if macro_args. len( ) == 2 ;
82
- let ( lhs, rhs) = ( macro_args[ 0 ] , macro_args[ 1 ] ) ;
83
- if eq_expr_value( cx, lhs, rhs) ;
75
+ if !is_in_test_function ( cx. tcx , e. hir_id ) {
76
+ for stmt in block. stmts {
77
+ for amn in & ASSERT_MACRO_NAMES {
78
+ if_chain ! {
79
+ if is_expn_of( stmt. span, amn) . is_some( ) ;
80
+ if let StmtKind :: Semi ( matchexpr) = stmt. kind;
81
+ if let Some ( macro_args) = higher:: extract_assert_macro_args( matchexpr) ;
82
+ if macro_args. len( ) == 2 ;
83
+ let ( lhs, rhs) = ( macro_args[ 0 ] , macro_args[ 1 ] ) ;
84
+ if eq_expr_value( cx, lhs, rhs) ;
84
85
85
- then {
86
- span_lint(
87
- cx,
88
- EQ_OP ,
89
- lhs. span. to( rhs. span) ,
90
- & format!( "identical args used in this `{}!` macro call" , amn) ,
91
- ) ;
86
+ then {
87
+ span_lint(
88
+ cx,
89
+ EQ_OP ,
90
+ lhs. span. to( rhs. span) ,
91
+ & format!( "identical args used in this `{}!` macro call" , amn) ,
92
+ ) ;
93
+ }
92
94
}
93
95
}
94
96
}
@@ -108,7 +110,10 @@ impl<'tcx> LateLintPass<'tcx> for EqOp {
108
110
if macro_with_not_op ( & left. kind ) || macro_with_not_op ( & right. kind ) {
109
111
return ;
110
112
}
111
- if is_useless_with_eq_exprs ( op. node . into ( ) ) && eq_expr_value ( cx, left, right) {
113
+ if is_useless_with_eq_exprs ( op. node . into ( ) )
114
+ && !is_in_test_function ( cx. tcx , e. hir_id )
115
+ && eq_expr_value ( cx, left, right)
116
+ {
112
117
span_lint (
113
118
cx,
114
119
EQ_OP ,
0 commit comments