aboutsummaryrefslogtreecommitdiff
path: root/lib/std/hash_map.zig
diff options
context:
space:
mode:
authorJulius Putra Tanu Setiaji <indocomsoft@gmail.com>2020-12-28 09:43:52 +0800
committerAndrew Kelley <andrew@ziglang.org>2021-01-07 23:51:53 -0800
commit2b3b355a23bea47aacbdfd56b853abc83e2f3ed6 (patch)
treec00b8458ae5cdf6071b50b6f8d6062cb2f1b1cba /lib/std/hash_map.zig
parent3fdffe85c0e51d1ec27e6ab4367a6293c18ce44c (diff)
downloadzig-2b3b355a23bea47aacbdfd56b853abc83e2f3ed6.tar.gz
zig-2b3b355a23bea47aacbdfd56b853abc83e2f3ed6.zip
Add compileError message for StringHashMap in AutoHashMap
Diffstat (limited to 'lib/std/hash_map.zig')
-rw-r--r--lib/std/hash_map.zig11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/std/hash_map.zig b/lib/std/hash_map.zig
index 8e32d12c55..679575875d 100644
--- a/lib/std/hash_map.zig
+++ b/lib/std/hash_map.zig
@@ -17,6 +17,17 @@ const Allocator = mem.Allocator;
const Wyhash = std.hash.Wyhash;
pub fn getAutoHashFn(comptime K: type) (fn (K) u64) {
+ comptime {
+ assert(@hasDecl(std, "StringHashMap")); // detect when the following message needs updated
+ if (K == []const u8) {
+ @compileError("std.auto_hash.autoHash does not allow slices here (" ++
+ @typeName(K) ++
+ ") because the intent is unclear. " ++
+ "Consider using std.StringHashMap for hashing the contents of []const u8. " ++
+ "Alternatively, consider using std.auto_hash.hash or providing your own hash function instead.");
+ }
+ }
+
return struct {
fn hash(key: K) u64 {
if (comptime trait.hasUniqueRepresentation(K)) {