Skip to content

let_unit_value suggestion mangles macros #15784

@ada4a

Description

@ada4a

Summary

If a let statement simultaneously:

  • has an initializer which:
    • is a macro call
    • resolves to a unit
  • is used inline in a format_args!

Then the suggested replacement mangles the initializer macro call

Reproducer

I tried this code:

#![allow(unused)]
#![warn(clippy::let_unit_value)]

fn do_something(x: ()) {}

fn foo() {
    let res = eprintln!("I return unit");
    println!("{res:?}");
}

I expected to see this happen:

warning: this let-binding has unit value
 --> src/main.rs:7:5
  |
7 |     let res = eprintln!("I return unit");
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
note: the lint level is defined here
 --> src/main.rs:2:9
  |
2 | #![warn(clippy::let_unit_value)]
  |         ^^^^^^^^^^^^^^^^^^^^^^
help: replace variable usages with `()`
 --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/macros.rs:220:23
  |
7 ~     let res = ();
8 ~     eprintln!("I return unit")};
  |

Instead, this happened:

help: replace variable usages with `()`
 --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/macros.rs:220:23
  |
22~     ($($arg:tt)*) => {();
22~     eprintln!("I return unit")};
  |

Version

rustc 1.92.0-nightly (c8905eaa6 2025-09-28)
binary: rustc
commit-hash: c8905eaa66e0c35a33626e974b9ce6955c739b5b
commit-date: 2025-09-28
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.2

Additional Labels

@rustbot label I-suggestion-causes-error

@rustbot claim

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