diff --git a/lib/std/meta.zig b/lib/std/meta.zig index 13c7731c5514..0fff0aed3c65 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -1200,6 +1200,8 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool { .Array => |info| hasUniqueRepresentation(info.child), .Struct => |info| { + if (info.layout == .@"packed") return @sizeOf(T) * 8 == @bitSizeOf(T); + var sum_size = @as(usize, 0); inline for (info.fields) |field| { @@ -1245,6 +1247,19 @@ test hasUniqueRepresentation { try testing.expect(!hasUniqueRepresentation(TestStruct5)); + const TestStruct6 = packed struct(u8) { + @"0": bool, + @"1": bool, + @"2": bool, + @"3": bool, + @"4": bool, + @"5": bool, + @"6": bool, + @"7": bool, + }; + + try testing.expect(hasUniqueRepresentation(TestStruct6)); + const TestUnion1 = packed union { a: u32, b: u16,