Fix unused_unit macro false positive

This commit is contained in:
Cameron Steffen 2021-05-04 17:20:15 -05:00
parent a8f28b6365
commit 83329ec705
3 changed files with 17 additions and 1 deletions

View file

@ -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(

View file

@ -80,3 +80,10 @@ fn test2(){}
#[rustfmt::skip]
fn test3(){}
fn macro_expr() {
macro_rules! e {
() => (());
}
e!()
}

View file

@ -80,3 +80,10 @@ fn test2() ->(){}
#[rustfmt::skip]
fn test3()-> (){}
fn macro_expr() {
macro_rules! e {
() => (());
}
e!()
}