From ac917993329076170d7a25ae5d7a9e822fb388ad Mon Sep 17 00:00:00 2001 From: Ian Johnson Date: Wed, 7 Jan 2026 23:06:35 -0500 Subject: [PATCH] std.meta.hasUniqueRepresentation: consider enum tag type Closes #30731 --- lib/std/meta.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/std/meta.zig b/lib/std/meta.zig index 677e359b34473cad228362bd22854e754c704b11..a4ce8161327e9ebebe5003810aac81e0d5c18c32 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -983,13 +983,13 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool { else => false, // TODO can we know if it's true for some of these types ? .@"anyframe", - .@"enum", .error_set, .@"fn", => true, .bool => false, + .@"enum" => |info| hasUniqueRepresentation(info.tag_type), .int => |info| @sizeOf(T) * 8 == info.bits, .pointer => |info| info.size != .slice, @@ -1089,9 +1089,11 @@ test hasUniqueRepresentation { inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| { try testing.expect(hasUniqueRepresentation(T)); + try testing.expect(hasUniqueRepresentation(enum(T) { _ })); } inline for ([_]type{ i1, u9, i17, u33, i24 }) |T| { try testing.expect(!hasUniqueRepresentation(T)); + try testing.expect(!hasUniqueRepresentation(enum(T) { _ })); } try testing.expect(hasUniqueRepresentation(*u8)); -- 2.54.0