File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -1200,6 +1200,8 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {
12001200 .Array = > | info | hasUniqueRepresentation (info .child ),
12011201
12021202 .Struct = > | info | {
1203+ if (info .layout == .@"packed" ) return @sizeOf (T ) * 8 == @bitSizeOf (T );
1204+
12031205 var sum_size = @as (usize , 0 );
12041206
12051207 inline for (info .fields ) | field | {
@@ -1245,6 +1247,19 @@ test hasUniqueRepresentation {
12451247
12461248 try testing .expect (! hasUniqueRepresentation (TestStruct5 ));
12471249
1250+ const TestStruct6 = packed struct (u8 ) {
1251+ @"0" : bool ,
1252+ @"1" : bool ,
1253+ @"2" : bool ,
1254+ @"3" : bool ,
1255+ @"4" : bool ,
1256+ @"5" : bool ,
1257+ @"6" : bool ,
1258+ @"7" : bool ,
1259+ };
1260+
1261+ try testing .expect (hasUniqueRepresentation (TestStruct6 ));
1262+
12481263 const TestUnion1 = packed union {
12491264 a : u32 ,
12501265 b : u16 ,
You can’t perform that action at this time.
0 commit comments