Cargo clippy --fix seems to not respect black_box
⚓ Rust 📅 2026-02-16 👤 surdeus 👁️ 1Hi everyone,
One of my colleagues just tried running cargo clippy --fix on our benchmark targets, (using 1.95 on the nightly channel) and it converted this:
black_box(hasher.write(&data));
To this:
let _: () = hasher.write(&data);
black_box(());
This clippy rule is this one:
warning: passing a unit value to a function
--> crates\fxv_multicas\benches\hash_hashing.rs:11:5
|
11 | black_box(hasher.write(&data));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
= note: `#[warn(clippy::unit_arg)]` on by default
The goal is to ensure that hasher.write is not optimized away in my benchmark, though perhaps that's not even necessary in this case. We do have some other slightly more complex cases where it does the same thing.
Given black_box()'s special status, should this still happen, i.e. is it a bug? It feels like it is a special case bug since black_box is a compiler hint, but I don't know enough to be sure.
Is the workaround just to #[allow(clippy::unit_arg)] in these functions? Is there a way to make it such that it leaves black_box alone always?
4 posts - 3 participants
🏷️ Rust_feed