authorgravatar for benjamin.feng@glassdoor.comBenjamin Feng <benjamin.feng@glassdoor.com> 2020-04-05 12:26:26-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-05 18:38:19-04:00
logcb98984ae6fa73ab3e4ad660af272d8604f513fa
tree41281b7c6d8d95c850c9342e5b6178109e957d4b
parent05b587fcdee91a7c9f170da4a186a512b51b39a8

Generate clearer size mismatch error message


1 files changed, 3 insertions(+), 2 deletions(-)

lib/std/mem.zig+3-2
...@@ -501,7 +501,7 @@ pub const toSlice = @compileError("deprecated; use std.mem.spanZ");...@@ -501,7 +501,7 @@ pub const toSlice = @compileError("deprecated; use std.mem.spanZ");
501/// the constness of the input type. `[*c]` pointers are assumed to be 0-terminated,501/// the constness of the input type. `[*c]` pointers are assumed to be 0-terminated,
502/// and assumed to not allow null.502/// and assumed to not allow null.
503pub fn Span(comptime T: type) type {503pub fn Span(comptime T: type) type {
504 switch(@typeInfo(T)) {504 switch (@typeInfo(T)) {
505 .Optional => |optional_info| {505 .Optional => |optional_info| {
506 return ?Span(optional_info.child);506 return ?Span(optional_info.child);
507 },507 },
...@@ -1758,7 +1758,8 @@ fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {...@@ -1758,7 +1758,8 @@ fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {
1758 if (comptime !trait.is(.Pointer)(B) or1758 if (comptime !trait.is(.Pointer)(B) or
1759 (meta.Child(B) != [size]u8 and meta.Child(B) != [size:0]u8))1759 (meta.Child(B) != [size]u8 and meta.Child(B) != [size:0]u8))
1760 {1760 {
1761 @compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B));1761 comptime var buf: [100]u8 = undefined;
1762 @compileError(std.fmt.bufPrint(&buf, "expected *[{}]u8, passed " ++ @typeName(B), .{size}) catch unreachable);
1762 }1763 }
17631764
1764 const alignment = comptime meta.alignment(B);1765 const alignment = comptime meta.alignment(B);