commit cb98984ae6fa73ab3e4ad660af272d8604f513fa (tree)
parent 05b587fcdee91a7c9f170da4a186a512b51b39a8
Author: Benjamin Feng <benjamin.feng@glassdoor.com>
Date: Sun, 5 Apr 2020 12:26:26 -0500
Generate clearer size mismatch error message
Diffstat:
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/std/mem.zig b/lib/std/mem.zig
@@ -501,7 +501,7 @@ pub const toSlice = @compileError("deprecated; use std.mem.spanZ");
/// the constness of the input type. `[*c]` pointers are assumed to be 0-terminated,
/// and assumed to not allow null.
pub fn Span(comptime T: type) type {
- switch(@typeInfo(T)) {
+ switch (@typeInfo(T)) {
.Optional => |optional_info| {
return ?Span(optional_info.child);
},
@@ -1758,7 +1758,8 @@ fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {
if (comptime !trait.is(.Pointer)(B) or
(meta.Child(B) != [size]u8 and meta.Child(B) != [size:0]u8))
{
- @compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B));
+ comptime var buf: [100]u8 = undefined;
+ @compileError(std.fmt.bufPrint(&buf, "expected *[{}]u8, passed " ++ @typeName(B), .{size}) catch unreachable);
}
const alignment = comptime meta.alignment(B);