Skip to content

Commit 64df858

Browse files
Implement KnownLayout for f16 and f128 (#2250) (#2312)
Co-authored-by: usamoi <[email protected]>
1 parent 3acb652 commit 64df858

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/impls.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,16 @@ mod tests {
15381538
IntoBytes,
15391539
!Unaligned
15401540
);
1541+
#[cfg(feature = "float-nightly")]
1542+
assert_impls!(
1543+
f16: KnownLayout,
1544+
Immutable,
1545+
TryFromBytes,
1546+
FromZeros,
1547+
FromBytes,
1548+
IntoBytes,
1549+
!Unaligned
1550+
);
15411551
assert_impls!(
15421552
f32: KnownLayout,
15431553
Immutable,
@@ -1556,7 +1566,16 @@ mod tests {
15561566
IntoBytes,
15571567
!Unaligned
15581568
);
1559-
1569+
#[cfg(feature = "float-nightly")]
1570+
assert_impls!(
1571+
f128: KnownLayout,
1572+
Immutable,
1573+
TryFromBytes,
1574+
FromZeros,
1575+
FromBytes,
1576+
IntoBytes,
1577+
!Unaligned
1578+
);
15601579
assert_impls!(
15611580
bool: KnownLayout,
15621581
Immutable,

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,14 @@ impl_known_layout!(
929929
NonZeroU64, NonZeroI64, NonZeroU128, NonZeroI128, NonZeroUsize, NonZeroIsize
930930
);
931931
#[rustfmt::skip]
932+
#[cfg(feature = "float-nightly")]
933+
impl_known_layout!(
934+
#[cfg_attr(doc_cfg, doc(cfg(feature = "float-nightly")))]
935+
f16,
936+
#[cfg_attr(doc_cfg, doc(cfg(feature = "float-nightly")))]
937+
f128
938+
);
939+
#[rustfmt::skip]
932940
impl_known_layout!(
933941
T => Option<T>,
934942
T: ?Sized => PhantomData<T>,

src/util/macros.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,12 +532,13 @@ macro_rules! impl_known_layout {
532532
($($tyvar:ident $(: ?$optbound:ident)? => $ty:ty),* $(,)?) => {
533533
$(impl_known_layout!(@inner , $tyvar $(: ?$optbound)? => $ty);)*
534534
};
535-
($($ty:ty),*) => { $(impl_known_layout!(@inner , => $ty);)* };
536-
(@inner $(const $constvar:ident : $constty:ty)? , $($tyvar:ident $(: ?$optbound:ident)?)? => $ty:ty) => {
535+
($($(#[$attrs:meta])* $ty:ty),*) => { $(impl_known_layout!(@inner , => $(#[$attrs])* $ty);)* };
536+
(@inner $(const $constvar:ident : $constty:ty)? , $($tyvar:ident $(: ?$optbound:ident)?)? => $(#[$attrs:meta])* $ty:ty) => {
537537
const _: () = {
538538
use core::ptr::NonNull;
539539

540540
#[allow(non_local_definitions)]
541+
$(#[$attrs])*
541542
// SAFETY: Delegates safety to `DstLayout::for_type`.
542543
unsafe impl<$($tyvar $(: ?$optbound)?)? $(, const $constvar : $constty)?> KnownLayout for $ty {
543544
#[allow(clippy::missing_inline_in_public_items)]

0 commit comments

Comments
 (0)