authorgravatar for ian@ianjohnson.devIan Johnson <ian@ianjohnson.dev> 2026-01-07 23:06:35-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-08 09:24:12+01:00
logac917993329076170d7a25ae5d7a9e822fb388ad
tree574fd2964213c6966dd472aad728aba091017a56
parent6f7968f1658ef92fb878f0284af7761aaaa3e71a

std.meta.hasUniqueRepresentation: consider enum tag type

Closes #30731

1 files changed, 3 insertions(+), 1 deletions(-)

lib/std/meta.zig+3-1
......@@ -983,13 +983,13 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {
983983 else => false, // TODO can we know if it's true for some of these types ?
984984
985985 .@"anyframe",
986 .@"enum",
987986 .error_set,
988987 .@"fn",
989988 => true,
990989
991990 .bool => false,
992991
992 .@"enum" => |info| hasUniqueRepresentation(info.tag_type),
993993 .int => |info| @sizeOf(T) * 8 == info.bits,
994994
995995 .pointer => |info| info.size != .slice,
......@@ -1089,9 +1089,11 @@ test hasUniqueRepresentation {
10891089
10901090 inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| {
10911091 try testing.expect(hasUniqueRepresentation(T));
1092 try testing.expect(hasUniqueRepresentation(enum(T) { _ }));
10921093 }
10931094 inline for ([_]type{ i1, u9, i17, u33, i24 }) |T| {
10941095 try testing.expect(!hasUniqueRepresentation(T));
1096 try testing.expect(!hasUniqueRepresentation(enum(T) { _ }));
10951097 }
10961098
10971099 try testing.expect(hasUniqueRepresentation(*u8));