mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:44:43 +01:00
std.meta: handle comptime fields in hasUniqueRepresentation (#22132)
This commit is contained in:
parent
3179961854
commit
9c6d728b0c
1 changed files with 9 additions and 0 deletions
|
|
@ -1208,6 +1208,7 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {
|
|||
var sum_size = @as(usize, 0);
|
||||
|
||||
inline for (info.fields) |field| {
|
||||
if (field.is_comptime) continue;
|
||||
if (!hasUniqueRepresentation(field.type)) return false;
|
||||
sum_size += @sizeOf(field.type);
|
||||
}
|
||||
|
|
@ -1310,4 +1311,12 @@ test hasUniqueRepresentation {
|
|||
|
||||
try testing.expect(hasUniqueRepresentation(@Vector(std.simd.suggestVectorLength(u8) orelse 1, u8)));
|
||||
try testing.expect(@sizeOf(@Vector(3, u8)) == 3 or !hasUniqueRepresentation(@Vector(3, u8)));
|
||||
|
||||
const StructWithComptimeFields = struct {
|
||||
comptime should_be_ignored: u64 = 42,
|
||||
comptime should_also_be_ignored: [*:0]const u8 = "hope you're having a good day :)",
|
||||
field: u32,
|
||||
};
|
||||
|
||||
try testing.expect(hasUniqueRepresentation(StructWithComptimeFields));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue