authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-10-31 15:16:59+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-02 17:12:57-07:00
logd4a8fc8b67bd2ae26b997ee201545cbb1eb3c15f
treea7331e509adaefa385427e779a83b3a2d0d01f7b
parent2b5e93fd3ea7ced934c7310ce68177738b1cdb81

Small cleanup


1 files changed, 6 insertions(+), 7 deletions(-)

lib/std/fmt.zig+6-7
......@@ -463,12 +463,11 @@ pub fn formatType(
463463 try formatType(@enumToInt(value), fmt, options, writer, max_depth);
464464 try writer.writeAll(")");
465465 },
466 .Union => {
466 .Union => |info| {
467467 try writer.writeAll(@typeName(T));
468468 if (max_depth == 0) {
469469 return writer.writeAll("{ ... }");
470470 }
471 const info = @typeInfo(T).Union;
472471 if (info.tag_type) |UnionTagType| {
473472 try writer.writeAll("{ .");
474473 try writer.writeAll(@tagName(@as(UnionTagType, value)));
......@@ -507,30 +506,30 @@ pub fn formatType(
507506 if (info.child == u8) {
508507 return formatText(value, fmt, options, writer);
509508 }
510 return format(writer, "{}@{x}", .{ @typeName(@typeInfo(T).Pointer.child), @ptrToInt(value) });
509 return format(writer, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value) });
511510 },
512511 .Enum, .Union, .Struct => {
513512 return formatType(value.*, fmt, options, writer, max_depth);
514513 },
515 else => return format(writer, "{}@{x}", .{ @typeName(@typeInfo(T).Pointer.child), @ptrToInt(value) }),
514 else => return format(writer, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value) }),
516515 },
517516 .Many, .C => {
518517 if (ptr_info.sentinel) |sentinel| {
519518 return formatType(mem.span(value), fmt, options, writer, max_depth);
520519 }
521520 if (ptr_info.child == u8) {
522 if (fmt.len > 0 and fmt[0] == 's') {
521 if (fmt.len > 0 and comptime mem.indexOfScalar(u8, "sxXzZ", fmt[0]) != null) {
523522 return formatText(mem.span(value), fmt, options, writer);
524523 }
525524 }
526 return format(writer, "{}@{x}", .{ @typeName(@typeInfo(T).Pointer.child), @ptrToInt(value) });
525 return format(writer, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value) });
527526 },
528527 .Slice => {
529528 if (max_depth == 0) {
530529 return writer.writeAll("[ ... ]");
531530 }
532531 if (ptr_info.child == u8) {
533 if (fmt.len == 0 or fmt[0] == 's' or fmt[0] == 'x' or fmt[0] == 'X') {
532 if (fmt.len == 0 or comptime mem.indexOfScalar(u8, "sxXzZ", fmt[0]) != null) {
534533 return formatText(value, fmt, options, writer);
535534 }
536535 }