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