diff options
Diffstat (limited to 'src/docs/unit_hash.txt')
| -rw-r--r-- | src/docs/unit_hash.txt | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/docs/unit_hash.txt b/src/docs/unit_hash.txt new file mode 100644 index 00000000000..a22d2994602 --- /dev/null +++ b/src/docs/unit_hash.txt @@ -0,0 +1,20 @@ +### 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 { + Empty => ().hash(&mut state), + WithValue(x) => x.hash(&mut state), +} +``` +Use instead: +``` +match my_enum { + Empty => 0_u8.hash(&mut state), + WithValue(x) => x.hash(&mut state), +} +``` \ No newline at end of file |
