From 1ed1aaecf9d56cf13e3eb3dfc67808ac9e175569 Mon Sep 17 00:00:00 2001 From: zachs18 <8355914+zachs18@users.noreply.github.com> Date: Mon, 17 Jul 2023 11:01:10 -0500 Subject: [PATCH] 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/ --- src/checked.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/checked.rs b/src/checked.rs index 2eabfe8..a9c0e67 100644 --- a/src/checked.rs +++ b/src/checked.rs @@ -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 { ($($nonzero:ty: $primitive:ty),* $(,)?) => { $( @@ -178,14 +179,7 @@ macro_rules! impl_checked_for_nonzero { #[inline] fn is_valid_bit_pattern(bits: &Self::Bits) -> bool { - // Note(zachs18): The size and alignment check are almost certainly - // 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 + *bits != 0 } } )*