Skip to content

Commit f0d0fc6

Browse files
authored
Merge pull request rust-lang#2291 from DarrenTsung/fix_2265
Fix rust-lang#2265, ignore eq_op lint in macro invocation
2 parents 4daa4e3 + b9abe02 commit f0d0fc6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

clippy_lints/src/eq_op.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc::hir::*;
22
use rustc::lint::*;
3-
use utils::{implements_trait, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq};
3+
use utils::{in_macro, implements_trait, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq};
44

55
/// **What it does:** Checks for equal operands to comparison, logical and
66
/// bitwise, difference and division binary operators (`==`, `>`, etc., `&&`,
@@ -53,7 +53,7 @@ impl LintPass for EqOp {
5353
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
5454
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
5555
if let ExprBinary(ref op, ref left, ref right) = e.node {
56-
if is_valid_operator(op) && SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) {
56+
if is_valid_operator(op) && SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) && !in_macro(e.span) {
5757
span_lint(
5858
cx,
5959
EQ_OP,

tests/ui/eq_op.rs

+16
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,20 @@ fn main() {
8787
let x = Y(1);
8888
let y = Y(2);
8989
let z = x & &y;
90+
91+
check_ignore_macro();
92+
}
93+
94+
macro_rules! check_if_named_foo {
95+
($expression:expr) => (
96+
if stringify!($expression) == "foo" {
97+
println!("foo!");
98+
} else {
99+
println!("not foo.");
100+
}
101+
)
102+
}
103+
104+
fn check_ignore_macro() {
105+
check_if_named_foo!(foo);
90106
}

0 commit comments

Comments
 (0)