| ... | ... | @@ -1203,6 +1203,14 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool { |
| 1203 | 1203 | |
| 1204 | 1204 | .Pointer => |info| info.size != .Slice, |
| 1205 | 1205 | |
| 1206 | .Optional => |info| switch (@typeInfo(info.child)) { |
| 1207 | .Pointer => |ptr| !ptr.is_allowzero and switch (ptr.size) { |
| 1208 | .Slice, .C => false, |
| 1209 | .One, .Many => true, |
| 1210 | }, |
| 1211 | else => false, |
| 1212 | }, |
| 1213 | |
| 1206 | 1214 | .Array => |info| hasUniqueRepresentation(info.child), |
| 1207 | 1215 | |
| 1208 | 1216 | .Struct => |info| { |
| ... | ... | @@ -1301,8 +1309,15 @@ test hasUniqueRepresentation { |
| 1301 | 1309 | try testing.expect(!hasUniqueRepresentation(T)); |
| 1302 | 1310 | } |
| 1303 | 1311 | |
| 1312 | try testing.expect(hasUniqueRepresentation(*u8)); |
| 1313 | try testing.expect(hasUniqueRepresentation(*const u8)); |
| 1314 | try testing.expect(hasUniqueRepresentation(?*u8)); |
| 1315 | try testing.expect(hasUniqueRepresentation(?*const u8)); |
| 1316 | |
| 1304 | 1317 | try testing.expect(!hasUniqueRepresentation([]u8)); |
| 1305 | 1318 | try testing.expect(!hasUniqueRepresentation([]const u8)); |
| 1319 | try testing.expect(!hasUniqueRepresentation(?[]u8)); |
| 1320 | try testing.expect(!hasUniqueRepresentation(?[]const u8)); |
| 1306 | 1321 | |
| 1307 | 1322 | try testing.expect(hasUniqueRepresentation(@Vector(std.simd.suggestVectorLength(u8) orelse 1, u8))); |
| 1308 | 1323 | try testing.expect(@sizeOf(@Vector(3, u8)) == 3 or !hasUniqueRepresentation(@Vector(3, u8))); |