| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | const assert = std.debug.assert; |
| 3 | 4 | const mem = std.mem; |
| 4 | 5 | const meta = std.meta; |
| 5 | 6 | |
| ... | ... | @@ -165,8 +166,17 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void { |
| 165 | 166 | /// Slices are rejected to avoid ambiguity on the user's intention. |
| 166 | 167 | pub fn autoHash(hasher: var, key: var) void { |
| 167 | 168 | const Key = @typeOf(key); |
| 168 | | if (comptime meta.trait.isSlice(Key)) |
| 169 | | @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."); |
| 169 | if (comptime meta.trait.isSlice(Key)) { |
| 170 | comptime assert(@hasDecl(std, "StringHashMap")); // detect when the following message needs updated |
| 171 | const extra_help = if (Key == []const u8) |
| 172 | " Consider std.StringHashMap for hashing the contents of []const u8." |
| 173 | else |
| 174 | ""; |
| 175 | |
| 176 | @compileError("std.auto_hash.autoHash does not allow slices (here " ++ @typeName(Key) ++ |
| 177 | ") because the intent is unclear. Consider using std.auto_hash.hash or providing your own hash function instead." ++ |
| 178 | extra_help); |
| 179 | } |
| 170 | 180 | |
| 171 | 181 | hash(hasher, key, .Shallow); |
| 172 | 182 | } |