const std = @import("std");
const testing = std.testing;
const ZlibStreamHeader = packed struct {
cmf: u8,
flg: u8,
};
const zlibHeader = ZlibStreamHeader{
.cmf = 0x78,
.flg = 0x01,
};
test "reproduce 'error: out of bounds slice'" {
testing.expect(@sizeOf(@TypeOf(zlibHeader)) == 2);
const ptr1 = @ptrCast([*]const u8, &zlibHeader)[0..@sizeOf(@TypeOf(zlibHeader))];
//const ptr2 = @ptrCast([*]const u8, &zlibHeader)[0..2]; // same
}

This is with HEAD (2e53425). Possibly related issues: #1150, #1292
There's also some related discussion in https://github.com/ziglang/zig/issues/1738#issuecomment-440100426
I'm making a note to add coverage for this test case when doing #3133.