From 2d145b2ef5ab528434899d7b63c51a4bda1f7be9 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 13 Mar 2017 11:09:56 +0100 Subject: [PATCH] don't lint macro_rules! in items_after_statements --- clippy_lints/src/items_after_statements.rs | 4 ++++ tests/ui/item_after_statement.rs | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/clippy_lints/src/items_after_statements.rs b/clippy_lints/src/items_after_statements.rs index 3b3cd4237..5789f6a5f 100644 --- a/clippy_lints/src/items_after_statements.rs +++ b/clippy_lints/src/items_after_statements.rs @@ -58,6 +58,10 @@ impl EarlyLintPass for ItemsAfterStatements { if in_macro(cx, it.span) { return; } + if let ItemKind::MacroDef(..) = it.node { + // do not lint `macro_rules`, but continue processing further statements + continue; + } span_lint(cx, ITEMS_AFTER_STATEMENTS, it.span, diff --git a/tests/ui/item_after_statement.rs b/tests/ui/item_after_statement.rs index 09b509673..5ba94383c 100644 --- a/tests/ui/item_after_statement.rs +++ b/tests/ui/item_after_statement.rs @@ -17,3 +17,14 @@ fn main() { fn foo() { println!("foo"); } foo(); } + +fn mac() { + let mut a = 5; + println!("{}", a); + // do not lint this, because it needs to be after `a` + macro_rules! b { + () => {{ a = 6 }} + } + b!(); + println!("{}", a); +}