Auto merge of #7167 - camsteffen:unused-unit-macro, r=flip1995

Fix unused_unit macro false positive

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

Fixes #7055
This commit is contained in:
bors 2021-05-05 11:45:34 +00:00
commit 7e538e3522
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!()
}