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