Lokathor/bytemuck

bytes_of and bytes_of_mut run into unreachable code when T is a ZST

lizhuohua opened this issue · 1 comments

Hi, I noticed that the documentation of both bytes_of and bytes_of_mut says:

Any ZST becomes an empty slice

But instead of returning an empty slice, it actually causes a runtime panic. E.g., when executing:

use bytemuck;
fn main() {
    let zst: [u32; 0] = [];
    let _result = bytemuck::bytes_of(&zst);  // Panic: entered unreachable code
}

Well spotted. I'll try to fix this later today.