Skip to content

Commit

Permalink
UB fix: remove impl Zeroable for Infallible
Browse files Browse the repository at this point in the history
It is not enough for a type to be a ZST to guarantee that zeroed memory is a valid value for it; it must also be inhabited.  Creating a value of an uninhabited type, ZST or no, is immediate UB.
  • Loading branch information
pthariensflame authored Mar 8, 2024
1 parent 5b74366 commit c6dc132
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1485,8 +1485,9 @@ impl_zeroable! {
i8, i16, i32, i64, i128, isize,
f32, f64,

// SAFETY: These are ZSTs, there is nothing to zero.
{<T: ?Sized>} PhantomData<T>, core::marker::PhantomPinned, Infallible, (),
// SAFETY: These are inhabited ZSTs, there is nothing to zero
// and a valid value exists.
{<T: ?Sized>} PhantomData<T>, core::marker::PhantomPinned, (),

// SAFETY: Type is allowed to take any value, including all zeros.
{<T>} MaybeUninit<T>,
Expand Down

0 comments on commit c6dc132

Please sign in to comment.