| ... | @@ -463,12 +463,11 @@ pub fn formatType( | ... | @@ -463,12 +463,11 @@ pub fn formatType( |
| 463 | try formatType(@enumToInt(value), fmt, options, writer, max_depth); | 463 | try formatType(@enumToInt(value), fmt, options, writer, max_depth); |
| 464 | try writer.writeAll(")"); | 464 | try writer.writeAll(")"); |
| 465 | }, | 465 | }, |
| 466 | .Union => { | 466 | .Union => |info| { |
| 467 | try writer.writeAll(@typeName(T)); | 467 | try writer.writeAll(@typeName(T)); |
| 468 | if (max_depth == 0) { | 468 | if (max_depth == 0) { |
| 469 | return writer.writeAll("{ ... }"); | 469 | return writer.writeAll("{ ... }"); |
| 470 | } | 470 | } |
| 471 | const info = @typeInfo(T).Union; | | |
| 472 | if (info.tag_type) |UnionTagType| { | 471 | if (info.tag_type) |UnionTagType| { |
| 473 | try writer.writeAll("{ ."); | 472 | try writer.writeAll("{ ."); |
| 474 | try writer.writeAll(@tagName(@as(UnionTagType, value))); | 473 | try writer.writeAll(@tagName(@as(UnionTagType, value))); |
| ... | @@ -507,30 +506,30 @@ pub fn formatType( | ... | @@ -507,30 +506,30 @@ pub fn formatType( |
| 507 | if (info.child == u8) { | 506 | if (info.child == u8) { |
| 508 | return formatText(value, fmt, options, writer); | 507 | return formatText(value, fmt, options, writer); |
| 509 | } | 508 | } |
| 510 | return format(writer, "{}@{x}", .{ @typeName(@typeInfo(T).Pointer.child), @ptrToInt(value) }); | 509 | return format(writer, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value) }); |
| 511 | }, | 510 | }, |
| 512 | .Enum, .Union, .Struct => { | 511 | .Enum, .Union, .Struct => { |
| 513 | return formatType(value.*, fmt, options, writer, max_depth); | 512 | return formatType(value.*, fmt, options, writer, max_depth); |
| 514 | }, | 513 | }, |
| 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) }), |
| 516 | }, | 515 | }, |
| 517 | .Many, .C => { | 516 | .Many, .C => { |
| 518 | if (ptr_info.sentinel) |sentinel| { | 517 | if (ptr_info.sentinel) |sentinel| { |
| 519 | return formatType(mem.span(value), fmt, options, writer, max_depth); | 518 | return formatType(mem.span(value), fmt, options, writer, max_depth); |
| 520 | } | 519 | } |
| 521 | if (ptr_info.child == u8) { | 520 | 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) { |
| 523 | return formatText(mem.span(value), fmt, options, writer); | 522 | return formatText(mem.span(value), fmt, options, writer); |
| 524 | } | 523 | } |
| 525 | } | 524 | } |
| 526 | return format(writer, "{}@{x}", .{ @typeName(@typeInfo(T).Pointer.child), @ptrToInt(value) }); | 525 | return format(writer, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value) }); |
| 527 | }, | 526 | }, |
| 528 | .Slice => { | 527 | .Slice => { |
| 529 | if (max_depth == 0) { | 528 | if (max_depth == 0) { |
| 530 | return writer.writeAll("[ ... ]"); | 529 | return writer.writeAll("[ ... ]"); |
| 531 | } | 530 | } |
| 532 | if (ptr_info.child == u8) { | 531 | 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) { |
| 534 | return formatText(value, fmt, options, writer); | 533 | return formatText(value, fmt, options, writer); |
| 535 | } | 534 | } |
| 536 | } | 535 | } |