RS.CLIPPY.UNIT_HASH

Hashing a unit value, which does nothing

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: unit_hash. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Detects ().hash(_).

Why is this bad?

Hashing a unit value doesn't do anything as the implementation of Hash for () is a no-op.

Example

match my_enum {
\tEmpty => ().hash(&mut state),
\tWithValue(x) => x.hash(&mut state),
}

Use instead:

match my_enum {
\tEmpty => 0_u8.hash(&mut state),
\tWithValue(x) => x.hash(&mut state),
}