Skip to content

Commit eff3bc5

Browse files
committed
Auto merge of rust-lang#5079 - JohnTitor:fix-eq-op, r=flip1995
Ignore macros with `!` operators in `eq_op` `SpanlessEq::eq_expr` doesn't ignore macros with `!` operators and I'm not sure we should ignore there, so I ignore in `eq_op` (and `op_ref`). Fixes rust-lang#5077 changelog: Fix false positive in `eq_op`
2 parents 3e74853 + a7d58ed commit eff3bc5

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

clippy_lints/src/eq_op.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::utils::{implements_trait, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq};
1+
use crate::utils::{
2+
implements_trait, in_macro, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq,
3+
};
24
use rustc_errors::Applicability;
35
use rustc_hir::*;
46
use rustc_lint::{LateContext, LateLintPass};
@@ -53,6 +55,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
5355
if e.span.from_expansion() {
5456
return;
5557
}
58+
let macro_with_not_op = |expr_kind: &ExprKind<'_>| {
59+
if let ExprKind::Unary(_, ref expr) = *expr_kind {
60+
in_macro(expr.span)
61+
} else {
62+
false
63+
}
64+
};
65+
if macro_with_not_op(&left.kind) || macro_with_not_op(&right.kind) {
66+
return;
67+
}
5668
if is_valid_operator(op) && SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) {
5769
span_lint(
5870
cx,

tests/ui/eq_op.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ macro_rules! check_if_named_foo {
7373
)
7474
}
7575

76+
macro_rules! bool_macro {
77+
($expression:expr) => {
78+
true
79+
};
80+
}
81+
82+
#[allow(clippy::short_circuit_statement)]
7683
fn check_ignore_macro() {
7784
check_if_named_foo!(foo);
85+
// checks if the lint ignores macros with `!` operator
86+
!bool_macro!(1) && !bool_macro!("");
7887
}

0 commit comments

Comments
 (0)