From 50eb48e42b0be3dc124ad04eb14adfafabcaf155 Mon Sep 17 00:00:00 2001 From: Darren Tsung Date: Fri, 22 Dec 2017 10:37:44 -0800 Subject: [PATCH 1/3] Create failing test for equal inside macro --- tests/ui/eq_op.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/ui/eq_op.rs b/tests/ui/eq_op.rs index 89d85d1b3e9..70c932a6cdf 100644 --- a/tests/ui/eq_op.rs +++ b/tests/ui/eq_op.rs @@ -87,4 +87,20 @@ fn main() { let x = Y(1); let y = Y(2); let z = x & &y; + + check_ignore_macro(); +} + +macro_rules! check_if_named_foo { + ($expression:expr) => ( + if stringify!($expression) == "foo" { + println!("foo!"); + } else { + println!("not foo."); + } + ) +} + +fn check_ignore_macro() { + check_if_named_foo!(foo); } From 1f36aa519ee7ede53b8d788257ecb25174539942 Mon Sep 17 00:00:00 2001 From: Darren Tsung Date: Fri, 22 Dec 2017 10:51:41 -0800 Subject: [PATCH 2/3] =?UTF-8?q?Check=20that=20eq=5Fop=20lint=20doesn?= =?UTF-8?q?=E2=80=99t=20mark=20macro=20use=20of=20functions=20as=20errors?= =?UTF-8?q?=20since=20macros,=20fix=20#2265?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clippy_lints/src/eq_op.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index dbe0d68ad69..9bea91848dc 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -1,6 +1,6 @@ use rustc::hir::*; use rustc::lint::*; -use utils::{implements_trait, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq}; +use utils::{in_macro, implements_trait, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq}; /// **What it does:** Checks for equal operands to comparison, logical and /// bitwise, difference and division binary operators (`==`, `>`, etc., `&&`, @@ -53,7 +53,7 @@ impl LintPass for EqOp { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { if let ExprBinary(ref op, ref left, ref right) = e.node { - if is_valid_operator(op) && SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) { + if !in_macro(e.span) && is_valid_operator(op) && SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) { span_lint( cx, EQ_OP, From b9abe028c9d1df5df5871f431319bd60c34e7253 Mon Sep 17 00:00:00 2001 From: Darren Tsung Date: Fri, 22 Dec 2017 10:54:52 -0800 Subject: [PATCH 3/3] Move in_macro check to end of expression since usual case is not inside macro --- clippy_lints/src/eq_op.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index 9bea91848dc..d62b937f52f 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -53,7 +53,7 @@ impl LintPass for EqOp { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) { if let ExprBinary(ref op, ref left, ref right) = e.node { - if !in_macro(e.span) && 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) && !in_macro(e.span) { span_lint( cx, EQ_OP,