Commit 1091fee242

Michael Dusan <michael.dusan@gmail.com>
2020-03-05 18:19:08
std: format enum-literals
1 parent debcc79
Changed files (1)
lib
lib/std/fmt.zig
@@ -491,6 +491,13 @@ pub fn formatType(
             return format(context, Errors, output, "{}@{x}", .{ @typeName(T), @ptrToInt(value) });
         },
         .Type => return output(context, @typeName(T)),
+        .EnumLiteral => {
+            const name = @tagName(value);
+            var buffer: [name.len + 1]u8 = undefined;
+            buffer[0] = '.';
+            std.mem.copy(u8, buffer[1..], name);
+            return formatType(buffer, fmt, options, context, Errors, output, max_depth);
+        },
         else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"),
     }
 }
@@ -1744,3 +1751,7 @@ test "vector" {
     try testFmt("{ 1kB, 2kB, 3kB, 4kB }", "{B}", .{vu64});
     try testFmt("{ 1000B, 1.953125KiB, 2.9296875KiB, 3.90625KiB }", "{Bi}", .{vu64});
 }
+
+test "enum-literal" {
+    try testFmt(".hello_world", "{}", .{.hello_world});
+}