From f36f52091c94fdefa03068646cb13533d312109f Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Sat, 24 Aug 2019 21:42:39 +0200 Subject: [PATCH] Fix unused_unit false positive Fixes #4076 --- clippy_lints/src/returns.rs | 2 +- tests/ui/unused_unit.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 3cc053a0ebf6..e864518ee598 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -277,7 +277,7 @@ impl EarlyLintPass for Return { if_chain! { if let Some(ref stmt) = block.stmts.last(); if let ast::StmtKind::Expr(ref expr) = stmt.node; - if is_unit_expr(expr) && !expr.span.from_expansion(); + if is_unit_expr(expr) && !stmt.span.from_expansion(); then { let sp = expr.span; span_lint_and_then(cx, UNUSED_UNIT, sp, "unneeded unit expression", |db| { diff --git a/tests/ui/unused_unit.rs b/tests/ui/unused_unit.rs index 1acd427be1ee..e361755d50e0 100644 --- a/tests/ui/unused_unit.rs +++ b/tests/ui/unused_unit.rs @@ -43,3 +43,16 @@ fn main() { } return(); } + +// https://github.com/rust-lang/rust-clippy/issues/4076 +fn foo() { + macro_rules! foo { + (recv($r:expr) -> $res:pat => $body:expr) => { + $body + } + } + + foo! { + recv(rx) -> _x => () + } +}