Skip to content

useless_let_if_seq wrongly unmangled macros #16064

@profetia

Description

@profetia

Summary

useless_let_if_seq wrongly unmangled macros

Reproducer

Code:

fn issue16062(bar: fn() -> bool) {
    macro_rules! mac {
        ($e:expr) => {
            $e()
        };
        ($base:expr, $lit:expr) => {
            $lit * $base + 2
        };
    }

    let foo;
    if mac!(bar) {
        foo = mac!(10, 4);
    } else {
        foo = 0;
    }

    let bar = 1;
}

Current output:

15 | /     let foo;
16 | |     if mac!(bar) {
17 | |         foo = mac!(10, 4);
18 | |     } else {
19 | |         foo = 0;
20 | |     }
   | |_____^ help: it is more idiomatic to write: `let foo = if $e() { $base + 2 } else { 0 };`

Desired output:

15 | /     let foo;
16 | |     if mac!(bar) {
17 | |         foo = mac!(10, 4);
18 | |     } else {
19 | |         foo = 0;
20 | |     }
   | |_____^ help: it is more idiomatic to write: `let foo = if mac!(bar) { mac!(10, 4) } else { 0 };`

Version


Additional Labels

rustc 1.93.0-nightly (d5419f1e9 2025-10-30)
binary: rustc
commit-hash: d5419f1e97b90741d51841f800d3c697c662567d
commit-date: 2025-10-30
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.3

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thing

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions