std.MultiArrayList: check size of element, not pointer

Ever since a semi-recent language specification update, pointers to
zero-sized types still have runtime bits.
This commit is contained in:
Andrew Kelley 2022-03-24 19:55:12 -07:00
parent bb0e28a54f
commit b802a67562

View File

@ -42,7 +42,10 @@ pub fn MultiArrayList(comptime S: type) type {
return &[_]F{};
}
const byte_ptr = self.ptrs[@enumToInt(field)];
const casted_ptr: [*]F = if (@sizeOf([*]F) == 0) undefined else @ptrCast([*]F, @alignCast(@alignOf(F), byte_ptr));
const casted_ptr: [*]F = if (@sizeOf(F) == 0)
undefined
else
@ptrCast([*]F, @alignCast(@alignOf(F), byte_ptr));
return casted_ptr[0..self.len];
}