From e96a016e3fe9b942e66d24dc95e484323767f357 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sat, 30 May 2026 21:53:38 -0700 Subject: [PATCH] fmt: this enum behavior was super footgun-y --- fmt.zig | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/fmt.zig b/fmt.zig index 09490170335b998486c6f6d4291015be03fbf653..a1e98b8e45978da6840e1d167c76b2f995913261 100644 --- a/fmt.zig +++ b/fmt.zig @@ -467,27 +467,14 @@ fn formatType(value: anytype, comptime fmt: []const u8, options: FormatOptions, return writer.writeAll(@errorName(value)); }, .@"enum" => |enumInfo| { - try writer.writeAll(@typeName(T)); - if (enumInfo.is_exhaustive) { - if (actual_fmt.len != 0) invalidFmtError(fmt, value); - try writer.writeAll("."); + if (comptime std.mem.eql(u8, actual_fmt, "d")) { + try formatInt(@intFromEnum(value), 10, .lower, options, writer); + return; + } + if (comptime std.mem.eql(u8, actual_fmt, "s") and enumInfo.is_exhaustive) { try writer.writeAll(@tagName(value)); return; } - - // Use @tagName only if value is one of known fields - @setEvalBranchQuota(3 * enumInfo.fields.len); - inline for (enumInfo.fields) |enumField| { - if (@intFromEnum(value) == enumField.value) { - try writer.writeAll("."); - try writer.writeAll(@tagName(value)); - return; - } - } - - try writer.writeAll("("); - try formatType(@intFromEnum(value), actual_fmt, options, writer, max_depth); - try writer.writeAll(")"); }, .@"union" => |info| { if (actual_fmt.len != 0) invalidFmtError(fmt, value); -- 2.54.0