diff options
| author | Robin Voetter <robin@voetter.nl> | 2019-08-30 13:02:28 +0200 |
|---|---|---|
| committer | Robin Voetter <robin@voetter.nl> | 2019-08-30 13:02:28 +0200 |
| commit | ca2aa4880f468f12bcbe3d6cd315729dd361eff2 (patch) | |
| tree | 92bdee1022a3497b2f048e450b23d4e585a649f8 /std/hash/auto_hash.zig | |
| parent | 4b8325f3815c7fa774bb06ef5d190f039723222b (diff) | |
| parent | 10541c8fc88875cb51df0a5fdeda20847133e676 (diff) | |
| download | zig-ca2aa4880f468f12bcbe3d6cd315729dd361eff2.tar.gz zig-ca2aa4880f468f12bcbe3d6cd315729dd361eff2.zip | |
Merge remote-tracking branch 'upstream/master' into arm-support-improvement
Diffstat (limited to 'std/hash/auto_hash.zig')
| -rw-r--r-- | std/hash/auto_hash.zig | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/std/hash/auto_hash.zig b/std/hash/auto_hash.zig index dc65cada17..d34fc2719a 100644 --- a/std/hash/auto_hash.zig +++ b/std/hash/auto_hash.zig @@ -1,5 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); +const assert = std.debug.assert; const mem = std.mem; const meta = std.meta; @@ -165,8 +166,17 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void { /// Slices are rejected to avoid ambiguity on the user's intention. pub fn autoHash(hasher: var, key: var) void { const Key = @typeOf(key); - if (comptime meta.trait.isSlice(Key)) - @compileError("std.auto_hash.autoHash does not allow slices (here " ++ @typeName(Key) ++ " because the intent is unclear. Consider using std.auto_hash.hash or providing your own hash function instead."); + if (comptime meta.trait.isSlice(Key)) { + comptime assert(@hasDecl(std, "StringHashMap")); // detect when the following message needs updated + const extra_help = if (Key == []const u8) + " Consider std.StringHashMap for hashing the contents of []const u8." + else + ""; + + @compileError("std.auto_hash.autoHash does not allow slices (here " ++ @typeName(Key) ++ + ") because the intent is unclear. Consider using std.auto_hash.hash or providing your own hash function instead." ++ + extra_help); + } hash(hasher, key, .Shallow); } |
