authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-12-14 18:59:24+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-12-14 20:06:46+01:00
log44556bfebe8d06133c4dfc3cc2685ecb9d3babcd
treecb9ef3956b26fdc14b85da6efa623325aaca9e6a
parenta471a57560401c5562c4dc3e588227b689bf9487

std: non-byte-multiple sized integers have no definite representation

Closes #7445

1 files changed, 10 insertions(+), 11 deletions(-)

lib/std/meta/trait.zig+10-11
...@@ -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,
487486
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),
489492
490 .Struct => |info| {493 .Struct => |info| {
...@@ -525,14 +528,10 @@ test "std.meta.trait.hasUniqueRepresentation" {...@@ -525,14 +528,10 @@ test "std.meta.trait.hasUniqueRepresentation" {
525528
526 testing.expect(hasUniqueRepresentation(TestStruct3));529 testing.expect(hasUniqueRepresentation(TestStruct3));
527530
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}