Skip to content

Commit

Permalink
Auto merge of #12322 - sanxiyn:expression-with-attribute, r=llogiq
Browse files Browse the repository at this point in the history
Be careful with expressions with attributes

Fix #9949.

changelog: [`unused_unit`]: skip expressions with attributes
  • Loading branch information
bors committed Feb 24, 2024
2 parents 0597838 + cd45d5a commit 6405469
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions clippy_lints/src/unused_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl EarlyLintPass for UnusedUnit {
&& 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(
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/unused_unit.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,10 @@ mod issue9748 {
let _ = for<'a> |_: &'a u32| -> () {};
}
}

mod issue9949 {
fn main() {
#[doc = "documentation"]
()
}
}
7 changes: 7 additions & 0 deletions tests/ui/unused_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,10 @@ mod issue9748 {
let _ = for<'a> |_: &'a u32| -> () {};
}
}

mod issue9949 {
fn main() {
#[doc = "documentation"]
()
}
}

0 comments on commit 6405469

Please sign in to comment.