Skip to content

needless_if expands macro invocations #15959

@ada4a

Description

@ada4a

Summary

If the condition contains a macro invocation, the suggest will expand it to the macro definition

Reproducer

I tried this code:

fn foo() -> i32 {
    if matches!(2, 3) {}

    1 // put something here so that `if` is a statement not an expression
}

I expected to see this happen:

error: this `if` branch is empty
  --> tests/ui/needless_if.rs:110:5
   |
LL |     if matches!(2, 3) {}
   |     ^^^^^^^^^^^^^^^^^^^^
   |
help: you can remove it
   |
LL ~     matches!(2, 3);
   |

Instead, this happened:

error: this `if` branch is empty
  --> tests/ui/needless_if.rs:110:5
   |
LL |     if matches!(2, 3) {}
   |     ^^^^^^^^^^^^^^^^^^^^
   |
help: you can remove it
   |
LL ~     match $expression {
LL +             $pattern $(if $guard)? => true,
LL +             _ => false
LL +         };
   |

Version

rustc 1.90.0 (1159e78c4 2025-09-14)
binary: rustc
commit-hash: 1159e78c4747b02ef996e55082b704c09b970588
commit-date: 2025-09-14
host: x86_64-unknown-linux-gnu
release: 1.90.0
LLVM version: 20.1.8

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions