mirror of
https://github.com/Lokathor/bytemuck.git
synced 2024-11-21 14:22:26 +00:00
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:
parent
588d89082d
commit
1ed1aaecf9
@ -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
|
||||
}
|
||||
}
|
||||
)*
|
||||
|
Loading…
Reference in New Issue
Block a user