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); +}