-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
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 thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied