diff options
| author | bors <bors@rust-lang.org> | 2021-05-05 11:45:34 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-05-05 11:45:34 +0000 |
| commit | 7e538e3522797ed8fb9d4cbf6a01602fa76cae65 (patch) | |
| tree | 2fe84b936299a2f68e2069d1d4a72a32a1cceb61 | |
| parent | a8f28b636515cd859d8c9cc78dd17794f8a3c0ad (diff) | |
| parent | 83329ec7050da5093b0310ba3140c8c5ec093321 (diff) | |
| download | rust-7e538e3522797ed8fb9d4cbf6a01602fa76cae65.tar.gz rust-7e538e3522797ed8fb9d4cbf6a01602fa76cae65.zip | |
Auto merge of #7167 - camsteffen:unused-unit-macro, r=flip1995
Fix unused_unit macro false positive changelog: Fix [`unused_unit`] false positive with macros Fixes #7055
| -rw-r--r-- | clippy_lints/src/unused_unit.rs | 4 | ||||
| -rw-r--r-- | tests/ui/unused_unit.fixed | 7 | ||||
| -rw-r--r-- | tests/ui/unused_unit.rs | 7 |
3 files changed, 17 insertions, 1 deletions
diff --git a/clippy_lints/src/unused_unit.rs b/clippy_lints/src/unused_unit.rs index ce2d0b3ab2f..e14945651f5 100644 --- a/clippy_lints/src/unused_unit.rs +++ b/clippy_lints/src/unused_unit.rs @@ -47,7 +47,9 @@ impl EarlyLintPass for UnusedUnit { if_chain! { if let Some(stmt) = block.stmts.last(); if let ast::StmtKind::Expr(ref expr) = stmt.kind; - if is_unit_expr(expr) && !stmt.span.from_expansion(); + if is_unit_expr(expr); + let ctxt = block.span.ctxt(); + if stmt.span.ctxt() == ctxt && expr.span.ctxt() == ctxt; then { let sp = expr.span; span_lint_and_sugg( diff --git a/tests/ui/unused_unit.fixed b/tests/ui/unused_unit.fixed index a192ebde3eb..7bb43cf7ae8 100644 --- a/tests/ui/unused_unit.fixed +++ b/tests/ui/unused_unit.fixed @@ -80,3 +80,10 @@ fn test2(){} #[rustfmt::skip] fn test3(){} + +fn macro_expr() { + macro_rules! e { + () => (()); + } + e!() +} diff --git a/tests/ui/unused_unit.rs b/tests/ui/unused_unit.rs index 96041a7dd85..21073fb802a 100644 --- a/tests/ui/unused_unit.rs +++ b/tests/ui/unused_unit.rs @@ -80,3 +80,10 @@ fn test2() ->(){} #[rustfmt::skip] fn test3()-> (){} + +fn macro_expr() { + macro_rules! e { + () => (()); + } + e!() +} |
