linearize/impls/
infallible.rs

1use {crate::Linearize, core::convert::Infallible};
2
3// SAFETY:
4// - Storage and CopyStorage have the required type.
5// - linearize and from_linear_unchecked behave as required.
6unsafe impl Linearize for Infallible {
7    type Storage<T> = [T; Self::LENGTH];
8    type CopyStorage<T>
9        = [T; Self::LENGTH]
10    where
11        T: Copy;
12    const LENGTH: usize = 0;
13
14    #[inline]
15    fn linearize(&self) -> usize {
16        unsafe {
17            // SAFETY: Infallible is uninhabited.
18            cold_unreachable!();
19        }
20    }
21
22    #[inline]
23    unsafe fn from_linear_unchecked(_linear: usize) -> Self
24    where
25        Self: Sized,
26    {
27        unsafe {
28            // SAFETY: It's a precondition that _linear < Self::LENGTH = 0.
29            cold_unreachable!();
30        }
31    }
32}
33
34impl_assert!(Infallible, 0);