mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-20 10:55:14 +00:00
Auto merge of #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 #5077 changelog: Fix false positive in `eq_op`
This commit is contained in:
commit
eff3bc5e1e
@ -1,4 +1,6 @@
|
|||||||
use crate::utils::{implements_trait, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq};
|
use crate::utils::{
|
||||||
|
implements_trait, in_macro, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq,
|
||||||
|
};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::*;
|
use rustc_hir::*;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
@ -53,6 +55,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
|
|||||||
if e.span.from_expansion() {
|
if e.span.from_expansion() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let macro_with_not_op = |expr_kind: &ExprKind<'_>| {
|
||||||
|
if let ExprKind::Unary(_, ref expr) = *expr_kind {
|
||||||
|
in_macro(expr.span)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if macro_with_not_op(&left.kind) || macro_with_not_op(&right.kind) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if is_valid_operator(op) && SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) {
|
if is_valid_operator(op) && SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) {
|
||||||
span_lint(
|
span_lint(
|
||||||
cx,
|
cx,
|
||||||
|
@ -73,6 +73,15 @@ macro_rules! check_if_named_foo {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! bool_macro {
|
||||||
|
($expression:expr) => {
|
||||||
|
true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::short_circuit_statement)]
|
||||||
fn check_ignore_macro() {
|
fn check_ignore_macro() {
|
||||||
check_if_named_foo!(foo);
|
check_if_named_foo!(foo);
|
||||||
|
// checks if the lint ignores macros with `!` operator
|
||||||
|
!bool_macro!(1) && !bool_macro!("");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user