Rust logoRust/
RS-E1017

Attempting to hash a unit valueRS-E1017

Critical severityCritical
Bug Risk categoryBug Risk

Hashing a unit value does not do anything because Hash::hash for () is a no-op. Consider removing this .hash(_) call.

Bad practice

use std::collections::hash_map::DefaultHasher;
let mut hasher = DefaultHasher::new();

let item = ();
item.hash(&mut hasher); // no-op
let hash_res = hasher.finish();
use std::collections::hash_map::DefaultHasher;
let mut hasher = DefaultHasher::new();

// remove `hash` call
let item = ();
let hash_res = hasher.finish(); // remains the same