mirror of
https://github.com/ziglang/zig.git
synced 2025-01-10 20:21:16 +00:00
std.meta.hasUniqueRepresentation: Handle optional pointers correctly (#20366)
std.meta.hasUniqueRepresentation should now return true for non-slice optional pointers. Additional checks were added to the test to reflect this.
This commit is contained in:
parent
642093e04b
commit
f1b6f1aeb3
@ -1203,6 +1203,14 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {
|
||||
|
||||
.Pointer => |info| info.size != .Slice,
|
||||
|
||||
.Optional => |info| switch (@typeInfo(info.child)) {
|
||||
.Pointer => |ptr| !ptr.is_allowzero and switch (ptr.size) {
|
||||
.Slice, .C => false,
|
||||
.One, .Many => true,
|
||||
},
|
||||
else => false,
|
||||
},
|
||||
|
||||
.Array => |info| hasUniqueRepresentation(info.child),
|
||||
|
||||
.Struct => |info| {
|
||||
@ -1301,8 +1309,15 @@ test hasUniqueRepresentation {
|
||||
try testing.expect(!hasUniqueRepresentation(T));
|
||||
}
|
||||
|
||||
try testing.expect(hasUniqueRepresentation(*u8));
|
||||
try testing.expect(hasUniqueRepresentation(*const u8));
|
||||
try testing.expect(hasUniqueRepresentation(?*u8));
|
||||
try testing.expect(hasUniqueRepresentation(?*const u8));
|
||||
|
||||
try testing.expect(!hasUniqueRepresentation([]u8));
|
||||
try testing.expect(!hasUniqueRepresentation([]const u8));
|
||||
try testing.expect(!hasUniqueRepresentation(?[]u8));
|
||||
try testing.expect(!hasUniqueRepresentation(?[]const u8));
|
||||
|
||||
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)));
|
||||
|
Loading…
Reference in New Issue
Block a user