Remove FIXME and checks about NonZero[int] layout. (#199)

The layout was documented as guaranteed in 1.70.0 https://github.com/rust-lang/rust/pull/94786/
This commit is contained in:
zachs18 2023-07-17 11:01:10 -05:00 committed by GitHub
parent 588d89082d
commit 1ed1aaecf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -170,6 +170,7 @@ unsafe impl CheckedBitPattern for bool {
} }
} }
// Rust 1.70.0 documents that NonZero[int] has the same layout as [int].
macro_rules! impl_checked_for_nonzero { macro_rules! impl_checked_for_nonzero {
($($nonzero:ty: $primitive:ty),* $(,)?) => { ($($nonzero:ty: $primitive:ty),* $(,)?) => {
$( $(
@ -178,14 +179,7 @@ macro_rules! impl_checked_for_nonzero {
#[inline] #[inline]
fn is_valid_bit_pattern(bits: &Self::Bits) -> bool { fn is_valid_bit_pattern(bits: &Self::Bits) -> bool {
// Note(zachs18): The size and alignment check are almost certainly *bits != 0
// not necessary, but Rust currently doesn't explicitly document that
// NonZero[int] has the same layout as [int], so we check it to be safe.
// In a const to reduce debug-profile overhead.
const LAYOUT_SAME: bool =
core::mem::size_of::<$nonzero>() == core::mem::size_of::<$primitive>()
&& core::mem::align_of::<$nonzero>() == core::mem::align_of::<$primitive>();
LAYOUT_SAME && *bits != 0
} }
} }
)* )*