authorgravatar for indocomsoft@gmail.comJulius Putra Tanu Setiaji <indocomsoft@gmail.com> 2020-12-28 09:43:52+08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-07 23:51:53-08:00
log2b3b355a23bea47aacbdfd56b853abc83e2f3ed6
treec00b8458ae5cdf6071b50b6f8d6062cb2f1b1cba
parent3fdffe85c0e51d1ec27e6ab4367a6293c18ce44c

Add compileError message for StringHashMap in AutoHashMap


1 files changed, 11 insertions(+), 0 deletions(-)

lib/std/hash_map.zig+11
...@@ -17,6 +17,17 @@ const Allocator = mem.Allocator;...@@ -17,6 +17,17 @@ const Allocator = mem.Allocator;
17const Wyhash = std.hash.Wyhash;17const Wyhash = std.hash.Wyhash;
1818
19pub fn getAutoHashFn(comptime K: type) (fn (K) u64) {19pub fn getAutoHashFn(comptime K: type) (fn (K) u64) {
20 comptime {
21 assert(@hasDecl(std, "StringHashMap")); // detect when the following message needs updated
22 if (K == []const u8) {
23 @compileError("std.auto_hash.autoHash does not allow slices here (" ++
24 @typeName(K) ++
25 ") because the intent is unclear. " ++
26 "Consider using std.StringHashMap for hashing the contents of []const u8. " ++
27 "Alternatively, consider using std.auto_hash.hash or providing your own hash function instead.");
28 }
29 }
30
20 return struct {31 return struct {
21 fn hash(key: K) u64 {32 fn hash(key: K) u64 {
22 if (comptime trait.hasUniqueRepresentation(K)) {33 if (comptime trait.hasUniqueRepresentation(K)) {