From cd45d5a81c239ccced418604c8f60a4e5338c1e0 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Tue, 20 Feb 2024 22:18:49 +0900 Subject: [PATCH] Be careful with expressions with attributes --- clippy_lints/src/unused_unit.rs | 1 + tests/ui/unused_unit.fixed | 7 +++++++ tests/ui/unused_unit.rs | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/clippy_lints/src/unused_unit.rs b/clippy_lints/src/unused_unit.rs index 0a73da202ec..b70aa768b46 100644 --- a/clippy_lints/src/unused_unit.rs +++ b/clippy_lints/src/unused_unit.rs @@ -58,6 +58,7 @@ fn check_block(&mut self, cx: &EarlyContext<'_>, block: &ast::Block) { && let ctxt = block.span.ctxt() && stmt.span.ctxt() == ctxt && expr.span.ctxt() == ctxt + && expr.attrs.is_empty() { let sp = expr.span; span_lint_and_sugg( diff --git a/tests/ui/unused_unit.fixed b/tests/ui/unused_unit.fixed index 16da9a25b2a..04fe2d3b7af 100644 --- a/tests/ui/unused_unit.fixed +++ b/tests/ui/unused_unit.fixed @@ -94,3 +94,10 @@ mod issue9748 { let _ = for<'a> |_: &'a u32| -> () {}; } } + +mod issue9949 { + fn main() { + #[doc = "documentation"] + () + } +} diff --git a/tests/ui/unused_unit.rs b/tests/ui/unused_unit.rs index e374031436d..25c2ed59873 100644 --- a/tests/ui/unused_unit.rs +++ b/tests/ui/unused_unit.rs @@ -94,3 +94,10 @@ fn main() { let _ = for<'a> |_: &'a u32| -> () {}; } } + +mod issue9949 { + fn main() { + #[doc = "documentation"] + () + } +}