Skip to content

Commit

Permalink
Auto merge of rust-lang#7167 - camsteffen:unused-unit-macro, r=flip1995
Browse files Browse the repository at this point in the history
Fix unused_unit macro false positive

changelog: Fix [`unused_unit`] false positive with macros

Fixes rust-lang#7055
  • Loading branch information
bors committed May 5, 2021
2 parents a8f28b6 + 83329ec commit 7e538e3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clippy_lints/src/unused_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
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 @@ -80,3 +80,10 @@ fn test2(){}

#[rustfmt::skip]
fn test3(){}

fn macro_expr() {
macro_rules! e {
() => (());
}
e!()
}
7 changes: 7 additions & 0 deletions tests/ui/unused_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,10 @@ fn test2() ->(){}

#[rustfmt::skip]
fn test3()-> (){}

fn macro_expr() {
macro_rules! e {
() => (());
}
e!()
}

0 comments on commit 7e538e3

Please sign in to comment.