Skip to content

Commit 7e538e3

Browse files
committed
Auto merge of rust-lang#7167 - camsteffen:unused-unit-macro, r=flip1995
Fix unused_unit macro false positive changelog: Fix [`unused_unit`] false positive with macros Fixes rust-lang#7055
2 parents a8f28b6 + 83329ec commit 7e538e3

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

clippy_lints/src/unused_unit.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ impl EarlyLintPass for UnusedUnit {
4747
if_chain! {
4848
if let Some(stmt) = block.stmts.last();
4949
if let ast::StmtKind::Expr(ref expr) = stmt.kind;
50-
if is_unit_expr(expr) && !stmt.span.from_expansion();
50+
if is_unit_expr(expr);
51+
let ctxt = block.span.ctxt();
52+
if stmt.span.ctxt() == ctxt && expr.span.ctxt() == ctxt;
5153
then {
5254
let sp = expr.span;
5355
span_lint_and_sugg(

tests/ui/unused_unit.fixed

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,10 @@ fn test2(){}
8080

8181
#[rustfmt::skip]
8282
fn test3(){}
83+
84+
fn macro_expr() {
85+
macro_rules! e {
86+
() => (());
87+
}
88+
e!()
89+
}

tests/ui/unused_unit.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,10 @@ fn test2() ->(){}
8080

8181
#[rustfmt::skip]
8282
fn test3()-> (){}
83+
84+
fn macro_expr() {
85+
macro_rules! e {
86+
() => (());
87+
}
88+
e!()
89+
}

0 commit comments

Comments
 (0)