| ... | ... | @@ -467,27 +467,14 @@ fn formatType(value: anytype, comptime fmt: []const u8, options: FormatOptions, |
| 467 | 467 | return writer.writeAll(@errorName(value)); |
| 468 | 468 | }, |
| 469 | 469 | .@"enum" => |enumInfo| { |
| 470 | | try writer.writeAll(@typeName(T)); |
| 471 | | if (enumInfo.is_exhaustive) { |
| 472 | | if (actual_fmt.len != 0) invalidFmtError(fmt, value); |
| 473 | | try writer.writeAll("."); |
| 474 | | try writer.writeAll(@tagName(value)); |
| 470 | if (comptime std.mem.eql(u8, actual_fmt, "d")) { |
| 471 | try formatInt(@intFromEnum(value), 10, .lower, options, writer); |
| 475 | 472 | return; |
| 476 | 473 | } |
| 477 | | |
| 478 | | // Use @tagName only if value is one of known fields |
| 479 | | @setEvalBranchQuota(3 * enumInfo.fields.len); |
| 480 | | inline for (enumInfo.fields) |enumField| { |
| 481 | | if (@intFromEnum(value) == enumField.value) { |
| 482 | | try writer.writeAll("."); |
| 483 | | try writer.writeAll(@tagName(value)); |
| 484 | | return; |
| 485 | | } |
| 474 | if (comptime std.mem.eql(u8, actual_fmt, "s") and enumInfo.is_exhaustive) { |
| 475 | try writer.writeAll(@tagName(value)); |
| 476 | return; |
| 486 | 477 | } |
| 487 | | |
| 488 | | try writer.writeAll("("); |
| 489 | | try formatType(@intFromEnum(value), actual_fmt, options, writer, max_depth); |
| 490 | | try writer.writeAll(")"); |
| 491 | 478 | }, |
| 492 | 479 | .@"union" => |info| { |
| 493 | 480 | if (actual_fmt.len != 0) invalidFmtError(fmt, value); |