Hacker News new | ask | show | jobs
by celeritascelery 1033 days ago
Why couldn’t the Rust compiler also assume that dissimilar types don’t alias?
1 comments

Because existing unsafe code written in stable Rust depends on the ability to convert raw pointers and references from one type to another, as long as their memory layouts match. That's the whole premise of the bytemuck crate [0], and it's the basis for things like the &str-to-&[u8] or &[u8]-to-&str conversions in the standard library.

[0] https://docs.rs/bytemuck/latest/bytemuck/