zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit e8a9caa3dd0aef7b745b8197afecec90598b2cdd (tree)
parent af90da153178032df109aa955df0aac113de032d
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Wed, 28 Aug 2019 14:38:55 -0400

add suggestion to AutoHash compile error message

Diffstat:
Mstd/hash/auto_hash.zig | 14++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git 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); }