Skip to content

Commit

Permalink
Remove FIXME and checks about NonZero[int] layout.
Browse files Browse the repository at this point in the history
The layout was documented as guaranteed in 1.70.0 rust-lang/rust#94786
  • Loading branch information
zachs18 authored Jul 17, 2023
1 parent 588d890 commit 7423d74
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/checked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),* $(,)?) => {
$(
Expand All @@ -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
}
}
)*
Expand Down

0 comments on commit 7423d74

Please sign in to comment.