| ... | ... | @@ -481,10 +481,13 @@ pub fn hasUniqueRepresentation(comptime T: type) bool { |
| 481 | 481 | .Enum, |
| 482 | 482 | .ErrorSet, |
| 483 | 483 | .Fn, |
| 484 | | .Int, // TODO check that it is still true |
| 485 | 484 | .Pointer, |
| 486 | 485 | => return true, |
| 487 | 486 | |
| 487 | // The padding bits are undefined. |
| 488 | .Int => |info| return (info.bits % 8) == 0 and |
| 489 | (info.bits == 0 or std.math.isPowerOfTwo(info.bits)), |
| 490 | |
| 488 | 491 | .Array => |info| return comptime hasUniqueRepresentation(info.child), |
| 489 | 492 | |
| 490 | 493 | .Struct => |info| { |
| ... | ... | @@ -525,14 +528,10 @@ test "std.meta.trait.hasUniqueRepresentation" { |
| 525 | 528 | |
| 526 | 529 | testing.expect(hasUniqueRepresentation(TestStruct3)); |
| 527 | 530 | |
| 528 | | testing.expect(hasUniqueRepresentation(i1)); |
| 529 | | testing.expect(hasUniqueRepresentation(u2)); |
| 530 | | testing.expect(hasUniqueRepresentation(i3)); |
| 531 | | testing.expect(hasUniqueRepresentation(u4)); |
| 532 | | testing.expect(hasUniqueRepresentation(i5)); |
| 533 | | testing.expect(hasUniqueRepresentation(u6)); |
| 534 | | testing.expect(hasUniqueRepresentation(i7)); |
| 535 | | testing.expect(hasUniqueRepresentation(u8)); |
| 536 | | testing.expect(hasUniqueRepresentation(i9)); |
| 537 | | testing.expect(hasUniqueRepresentation(u10)); |
| 531 | inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| { |
| 532 | testing.expect(hasUniqueRepresentation(T)); |
| 533 | } |
| 534 | inline for ([_]type{ i1, u9, i17, u33, i24 }) |T| { |
| 535 | testing.expect(!hasUniqueRepresentation(T)); |
| 536 | } |
| 538 | 537 | } |