Skip to content

Commit 1ed1aae

Browse files
authored
Remove FIXME and checks about NonZero[int] layout. (#199)
The layout was documented as guaranteed in 1.70.0 rust-lang/rust#94786
1 parent 588d890 commit 1ed1aae

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/checked.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ unsafe impl CheckedBitPattern for bool {
170170
}
171171
}
172172

173+
// Rust 1.70.0 documents that NonZero[int] has the same layout as [int].
173174
macro_rules! impl_checked_for_nonzero {
174175
($($nonzero:ty: $primitive:ty),* $(,)?) => {
175176
$(
@@ -178,14 +179,7 @@ macro_rules! impl_checked_for_nonzero {
178179

179180
#[inline]
180181
fn is_valid_bit_pattern(bits: &Self::Bits) -> bool {
181-
// Note(zachs18): The size and alignment check are almost certainly
182-
// not necessary, but Rust currently doesn't explicitly document that
183-
// NonZero[int] has the same layout as [int], so we check it to be safe.
184-
// In a const to reduce debug-profile overhead.
185-
const LAYOUT_SAME: bool =
186-
core::mem::size_of::<$nonzero>() == core::mem::size_of::<$primitive>()
187-
&& core::mem::align_of::<$nonzero>() == core::mem::align_of::<$primitive>();
188-
LAYOUT_SAME && *bits != 0
182+
*bits != 0
189183
}
190184
}
191185
)*

0 commit comments

Comments
 (0)