authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-11-26 15:43:28+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-02 17:12:57-07:00
log1ca2deca33e5ee489e12bd71a34ec3e4a2e1255f
tree1646554a8d1428ea4c9d9990afd18ff53aaacfa6
parent4420afe64d5ae03565b51dcec55ce9dd7351d0ee

std: Disable the special casing of {} for u8 slices/arrays

Unless {s} is specified the contents won't be treated as a string.

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

lib/std/fmt.zig+4-2
......@@ -504,7 +504,9 @@ pub fn formatType(
504504 .One => switch (@typeInfo(ptr_info.child)) {
505505 .Array => |info| {
506506 if (info.child == u8) {
507 return formatText(value, fmt, options, writer);
507 if (fmt.len > 0 and comptime mem.indexOfScalar(u8, "sxXeEzZ", fmt[0]) != null) {
508 return formatText(value, fmt, options, writer);
509 }
508510 }
509511 return format(writer, "{s}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value) });
510512 },
......@@ -529,7 +531,7 @@ pub fn formatType(
529531 return writer.writeAll("{ ... }");
530532 }
531533 if (ptr_info.child == u8) {
532 if (fmt.len == 0 or comptime mem.indexOfScalar(u8, "sxXeEzZ", fmt[0]) != null) {
534 if (fmt.len > 0 and comptime mem.indexOfScalar(u8, "sxXeEzZ", fmt[0]) != null) {
533535 return formatText(value, fmt, options, writer);
534536 }
535537 }