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 {...@@ -983,13 +983,13 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {
983 else => false, // TODO can we know if it's true for some of these types ?983 else => false, // TODO can we know if it's true for some of these types ?
984984
985 .@"anyframe",985 .@"anyframe",
986 .@"enum",
987 .error_set,986 .error_set,
988 .@"fn",987 .@"fn",
989 => true,988 => true,
990989
991 .bool => false,990 .bool => false,
992991
992 .@"enum" => |info| hasUniqueRepresentation(info.tag_type),
993 .int => |info| @sizeOf(T) * 8 == info.bits,993 .int => |info| @sizeOf(T) * 8 == info.bits,
994994
995 .pointer => |info| info.size != .slice,995 .pointer => |info| info.size != .slice,
...@@ -1089,9 +1089,11 @@ test hasUniqueRepresentation {...@@ -1089,9 +1089,11 @@ test hasUniqueRepresentation {
10891089
1090 inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| {1090 inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| {
1091 try testing.expect(hasUniqueRepresentation(T));1091 try testing.expect(hasUniqueRepresentation(T));
1092 try testing.expect(hasUniqueRepresentation(enum(T) { _ }));
1092 }1093 }
1093 inline for ([_]type{ i1, u9, i17, u33, i24 }) |T| {1094 inline for ([_]type{ i1, u9, i17, u33, i24 }) |T| {
1094 try testing.expect(!hasUniqueRepresentation(T));1095 try testing.expect(!hasUniqueRepresentation(T));
1096 try testing.expect(!hasUniqueRepresentation(enum(T) { _ }));
1095 }1097 }
10961098
1097 try testing.expect(hasUniqueRepresentation(*u8));1099 try testing.expect(hasUniqueRepresentation(*u8));