Skip to content

Commit

Permalink
Fix unused_unit macro false positive
Browse files Browse the repository at this point in the history
  • Loading branch information
camsteffen committed May 4, 2021
1 parent a8f28b6 commit 83329ec
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 83329ec

Please sign in to comment.