Skip to content

Commit

Permalink
std: non-byte-multiple sized integers have no definite representation
Browse files Browse the repository at this point in the history
Closes #7445
  • Loading branch information
LemonBoy committed Dec 14, 2020
1 parent a471a57 commit 9bed868
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lib/std/meta/trait.zig
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,12 @@ pub fn hasUniqueRepresentation(comptime T: type) bool {
.Enum,
.ErrorSet,
.Fn,
.Int, // TODO check that it is still true
.Pointer,
=> return true,

// The padding bits are undefined.
.Int => |info| return (info.bits % 8) == 0,

.Array => |info| return comptime hasUniqueRepresentation(info.child),

.Struct => |info| {
Expand Down Expand Up @@ -525,14 +527,10 @@ test "std.meta.trait.hasUniqueRepresentation" {

testing.expect(hasUniqueRepresentation(TestStruct3));

testing.expect(hasUniqueRepresentation(i1));
testing.expect(hasUniqueRepresentation(u2));
testing.expect(hasUniqueRepresentation(i3));
testing.expect(hasUniqueRepresentation(u4));
testing.expect(hasUniqueRepresentation(i5));
testing.expect(hasUniqueRepresentation(u6));
testing.expect(hasUniqueRepresentation(i7));
testing.expect(hasUniqueRepresentation(u8));
testing.expect(hasUniqueRepresentation(i9));
testing.expect(hasUniqueRepresentation(u10));
inline for ([_]type{ i0, u8, i16, u32 }) |T| {
testing.expect(hasUniqueRepresentation(T));
}
inline for ([_]type{ i1, u9, i17, u33 }) |T| {
testing.expect(!hasUniqueRepresentation(T));
}
}

0 comments on commit 9bed868

Please sign in to comment.