Skip to content

Commit c6dc132

Browse files
UB fix: remove impl Zeroable for Infallible
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.
1 parent 5b74366 commit c6dc132

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,8 +1485,9 @@ impl_zeroable! {
14851485
i8, i16, i32, i64, i128, isize,
14861486
f32, f64,
14871487

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

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

0 commit comments

Comments
 (0)