Lokathor / bytemuck

A crate for mucking around with piles of bytes
https://docs.rs/bytemuck
Apache License 2.0
697 stars 77 forks source link

Address safety invariants in documentation #234

Open oskgo opened 5 months ago

oskgo commented 5 months ago

The safety documentation on AnyBitPattern mentions validity, but not safety.

From what I can tell an inhabited ZST with a trivially false safety invariant satisfies all the conditions listed (except the last, I guess).

mod foo {
    /// # SAFETY
    ///
    /// Sound APIs can assume that they will never observe values of this type
    pub struct UnsafelyInhabited{
        _priv: PhantomData<()>
    }

    pub fn explode(_ui: UnsafelyInhabited) {
        unsafe {unreachable_unchecked()}
    }
}
Lokathor commented 5 months ago

Fair point. the docs say "valid" when they should probably say something like "safe".