bytemuck icon indicating copy to clipboard operation
bytemuck copied to clipboard

Address safety invariants in documentation

Open oskgo opened this issue 2 years ago • 1 comments

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()}
    }
}

oskgo avatar Apr 12 '24 17:04 oskgo

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

Lokathor avatar Apr 12 '24 17:04 Lokathor