From 36de17d91e5e3ed9601afcca79a59020bffaa8e4 Mon Sep 17 00:00:00 2001 From: Juniper Tyree <50025784+juntyr@users.noreply.github.com> Date: Sun, 29 Sep 2024 14:58:14 +0000 Subject: [PATCH 1/7] Some progress with simplifying the inhabited computation --- const-type-layout-derive/src/lib.rs | 2 +- src/impls/core/array.rs | 3 +- src/impls/core/cell.rs | 12 +-- src/impls/core/cmp.rs | 6 +- src/impls/core/convert.rs | 3 +- src/impls/core/ffi.rs | 3 +- src/impls/core/fn.rs | 4 +- src/impls/core/marker.rs | 6 +- src/impls/core/mem.rs | 9 +- src/impls/core/num.rs | 8 +- src/impls/core/ops.rs | 21 ++--- src/impls/core/option.rs | 3 +- src/impls/core/pin.rs | 3 +- src/impls/core/primitive.rs | 5 +- src/impls/core/ptr.rs | 9 +- src/impls/core/ref.rs | 6 +- src/impls/core/result.rs | 3 +- src/impls/core/sync/atomic.rs | 6 +- src/impls/core/sync/mod.rs | 3 +- src/impls/core/tuple.rs | 2 +- src/inhabited.rs | 124 ++-------------------------- src/lib.rs | 32 +++++-- src/typeset.rs | 2 +- 23 files changed, 73 insertions(+), 202 deletions(-) diff --git a/const-type-layout-derive/src/lib.rs b/const-type-layout-derive/src/lib.rs index 30b561d..bae5be9 100644 --- a/const-type-layout-derive/src/lib.rs +++ b/const-type-layout-derive/src/lib.rs @@ -113,7 +113,7 @@ pub fn derive_type_layout(input: TokenStream) -> TokenStream { unsafe impl #type_layout_impl_generics #crate_path::TypeLayout for #ty_name #type_layout_ty_generics #type_layout_where_clause { - type Inhabited = #inhabited; + const INHABITED: #crate_path::inhabited::Inhabited = #inhabited; const TYPE_LAYOUT: #crate_path::TypeLayoutInfo<'static> = { #crate_path::TypeLayoutInfo { diff --git a/src/impls/core/array.rs b/src/impls/core/array.rs index 159bb98..f29092d 100644 --- a/src/impls/core/array.rs +++ b/src/impls/core/array.rs @@ -4,8 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for [T; N] { - type Inhabited = T::Inhabited; - + const INHABITED: crate::MaybeUninhabited = T::INHABITED; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/cell.rs b/src/impls/core/cell.rs index e794425..cdf0ecf 100644 --- a/src/impls/core/cell.rs +++ b/src/impls/core/cell.rs @@ -4,8 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for core::cell::UnsafeCell { - type Inhabited = T::Inhabited; - + const INHABITED: crate::MaybeUninhabited = T::INHABITED; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -26,8 +25,7 @@ unsafe impl ComputeTypeSet for core::cell::UnsafeCell { } unsafe impl TypeLayout for core::cell::Cell { - type Inhabited = T::Inhabited; - + const INHABITED: crate::MaybeUninhabited = T::INHABITED; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -48,8 +46,7 @@ unsafe impl ComputeTypeSet for core::cell::Cell { } unsafe impl TypeLayout for core::cell::SyncUnsafeCell { - type Inhabited = T::Inhabited; - + const INHABITED: crate::MaybeUninhabited = T::INHABITED; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -70,8 +67,7 @@ unsafe impl ComputeTypeSet for core::cell::SyncUnsafeCell } unsafe impl TypeLayout for core::cell::OnceCell { - type Inhabited = T::Inhabited; - + const INHABITED: crate::MaybeUninhabited = T::INHABITED; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/cmp.rs b/src/impls/core/cmp.rs index fe77561..e84d378 100644 --- a/src/impls/core/cmp.rs +++ b/src/impls/core/cmp.rs @@ -4,8 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for core::cmp::Reverse { - type Inhabited = T::Inhabited; - + const INHABITED: crate::MaybeUninhabited = T::INHABITED; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -26,8 +25,7 @@ unsafe impl ComputeTypeSet for core::cmp::Reverse { } unsafe impl TypeLayout for core::cmp::Ordering { - type Inhabited = crate::inhabited::Inhabited; - + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/convert.rs b/src/impls/core/convert.rs index ea09117..f29ce70 100644 --- a/src/impls/core/convert.rs +++ b/src/impls/core/convert.rs @@ -4,8 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for core::convert::Infallible { - type Inhabited = crate::inhabited::Uninhabited; - + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/ffi.rs b/src/impls/core/ffi.rs index 64cc3fa..8ba9297 100644 --- a/src/impls/core/ffi.rs +++ b/src/impls/core/ffi.rs @@ -4,8 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for core::ffi::c_void { - type Inhabited = crate::inhabited::Inhabited; - + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/fn.rs b/src/impls/core/fn.rs index 2b91876..2bf412c 100644 --- a/src/impls/core/fn.rs +++ b/src/impls/core/fn.rs @@ -20,7 +20,7 @@ macro_rules! impl_fn_pointer_type_layout { }; (impl extern $abi:literal fn($($T:ident),*) -> $R:ident, $ty:ty, $demo:item) => { unsafe impl<$R: TypeLayout, $($T: TypeLayout),*> TypeLayout for $ty { - type Inhabited = crate::inhabited::Inhabited; + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), @@ -63,7 +63,7 @@ macro_rules! impl_variadic_extern_fn_pointer_type_layout { unsafe impl<$R: TypeLayout, $($T: TypeLayout),*> TypeLayout for unsafe extern $abi fn($($T),*, ...) -> $R { - type Inhabited = crate::inhabited::Inhabited; + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), diff --git a/src/impls/core/marker.rs b/src/impls/core/marker.rs index bb6e2dd..6b8090e 100644 --- a/src/impls/core/marker.rs +++ b/src/impls/core/marker.rs @@ -4,8 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for core::marker::PhantomData { - type Inhabited = crate::inhabited::Inhabited; - + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -22,8 +21,7 @@ unsafe impl ComputeTypeSet for core::marker::PhantomData { } unsafe impl TypeLayout for core::marker::PhantomPinned { - type Inhabited = crate::inhabited::Inhabited; - + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/mem.rs b/src/impls/core/mem.rs index d738230..3df1b80 100644 --- a/src/impls/core/mem.rs +++ b/src/impls/core/mem.rs @@ -4,8 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for core::mem::ManuallyDrop { - type Inhabited = T::Inhabited; - + const INHABITED: crate::MaybeUninhabited = T::INHABITED; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -26,8 +25,7 @@ unsafe impl ComputeTypeSet for core::mem::ManuallyDrop { } unsafe impl TypeLayout for core::mem::MaybeUninit { - type Inhabited = crate::inhabited::Inhabited; - + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -55,8 +53,7 @@ unsafe impl ComputeTypeSet for core::mem::MaybeUninit { } unsafe impl TypeLayout for core::mem::Discriminant { - type Inhabited = crate::inhabited::Inhabited; - + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/num.rs b/src/impls/core/num.rs index 0a2c62f..9e9fd8e 100644 --- a/src/impls/core/num.rs +++ b/src/impls/core/num.rs @@ -6,7 +6,7 @@ use crate::{ macro_rules! impl_nonzero_type_layout { (impl $nz:ident => $ty:ty) => { unsafe impl TypeLayout for core::num::$nz { - type Inhabited = crate::inhabited::Inhabited; + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), @@ -42,8 +42,7 @@ impl_nonzero_type_layout! { } unsafe impl TypeLayout for core::num::Wrapping { - type Inhabited = T::Inhabited; - + const INHABITED: crate::MaybeUninhabited = T::INHABITED; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -64,8 +63,7 @@ unsafe impl ComputeTypeSet for core::num::Wrapping { } unsafe impl TypeLayout for core::num::Saturating { - type Inhabited = T::Inhabited; - + const INHABITED: crate::MaybeUninhabited = T::INHABITED; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/ops.rs b/src/impls/core/ops.rs index b9c8b12..b5f031c 100644 --- a/src/impls/core/ops.rs +++ b/src/impls/core/ops.rs @@ -4,8 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for core::ops::Range { - type Inhabited = Idx::Inhabited; - + const INHABITED: crate::MaybeUninhabited = Idx::INHABITED; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -33,8 +32,7 @@ unsafe impl ComputeTypeSet for core::ops::Range { } unsafe impl TypeLayout for core::ops::RangeFrom { - type Inhabited = Idx::Inhabited; - + const INHABITED: crate::MaybeUninhabited = Idx::INHABITED; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -55,8 +53,7 @@ unsafe impl ComputeTypeSet for core::ops::RangeFrom { } unsafe impl TypeLayout for core::ops::RangeFull { - type Inhabited = crate::inhabited::Inhabited; - + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -73,8 +70,7 @@ unsafe impl ComputeTypeSet for core::ops::RangeFull { } unsafe impl TypeLayout for core::ops::RangeTo { - type Inhabited = Idx::Inhabited; - + const INHABITED: crate::MaybeUninhabited = Idx::INHABITED; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -95,8 +91,7 @@ unsafe impl ComputeTypeSet for core::ops::RangeTo { } unsafe impl TypeLayout for core::ops::RangeToInclusive { - type Inhabited = Idx::Inhabited; - + const INHABITED: crate::MaybeUninhabited = Idx::INHABITED; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -117,8 +112,7 @@ unsafe impl ComputeTypeSet for core::ops::RangeToInclusive< } unsafe impl TypeLayout for core::ops::Bound { - type Inhabited = crate::inhabited::Inhabited; - + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -165,8 +159,7 @@ unsafe impl ComputeTypeSet for core::ops::Bound { } unsafe impl TypeLayout for core::ops::ControlFlow { - type Inhabited = crate::inhabited::any![B, C]; - + const INHABITED: crate::MaybeUninhabited = crate::inhabited::any![B, C]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/option.rs b/src/impls/core/option.rs index 0d33823..37a755a 100644 --- a/src/impls/core/option.rs +++ b/src/impls/core/option.rs @@ -4,8 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for core::option::Option { - type Inhabited = crate::inhabited::Inhabited; - + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/pin.rs b/src/impls/core/pin.rs index cc7df2a..6d9ea6c 100644 --- a/src/impls/core/pin.rs +++ b/src/impls/core/pin.rs @@ -4,8 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for core::pin::Pin { - type Inhabited = T::Inhabited; - + const INHABITED: crate::MaybeUninhabited = T::INHABITED; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/primitive.rs b/src/impls/core/primitive.rs index 35ce7b4..ec0bf2f 100644 --- a/src/impls/core/primitive.rs +++ b/src/impls/core/primitive.rs @@ -6,7 +6,7 @@ use crate::{ macro_rules! impl_primitive_type_layout { (impl $ty:ty => $val:expr) => { unsafe impl TypeLayout for $ty { - type Inhabited = crate::inhabited::Inhabited; + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), @@ -33,8 +33,7 @@ impl_primitive_type_layout! { } unsafe impl TypeLayout for ! { - type Inhabited = crate::inhabited::Uninhabited; - + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/ptr.rs b/src/impls/core/ptr.rs index d1a92c1..06d464e 100644 --- a/src/impls/core/ptr.rs +++ b/src/impls/core/ptr.rs @@ -4,8 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for *const T { - type Inhabited = crate::inhabited::Inhabited; - + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -19,8 +18,7 @@ unsafe impl ComputeTypeSet for *const T { } unsafe impl TypeLayout for *mut T { - type Inhabited = crate::inhabited::Inhabited; - + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -34,8 +32,7 @@ unsafe impl ComputeTypeSet for *mut T { } unsafe impl TypeLayout for core::ptr::NonNull { - type Inhabited = crate::inhabited::Inhabited; - + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/ref.rs b/src/impls/core/ref.rs index 135b3a1..f900c2c 100644 --- a/src/impls/core/ref.rs +++ b/src/impls/core/ref.rs @@ -4,8 +4,7 @@ use crate::{ }; unsafe impl<'a, T: TypeLayout + 'a> TypeLayout for &'a T { - type Inhabited = crate::inhabited::Inhabited; - + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -19,8 +18,7 @@ unsafe impl<'a, T: ComputeTypeSet + 'a> ComputeTypeSet for &'a T { } unsafe impl<'a, T: TypeLayout + 'a> TypeLayout for &'a mut T { - type Inhabited = crate::inhabited::Inhabited; - + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/result.rs b/src/impls/core/result.rs index 54b275e..cdfc958 100644 --- a/src/impls/core/result.rs +++ b/src/impls/core/result.rs @@ -4,8 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for core::result::Result { - type Inhabited = crate::inhabited::any![T, E]; - + const INHABITED: crate::MaybeUninhabited = crate::inhabited::any![T, E]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/sync/atomic.rs b/src/impls/core/sync/atomic.rs index 894cb15..8055ac8 100644 --- a/src/impls/core/sync/atomic.rs +++ b/src/impls/core/sync/atomic.rs @@ -7,7 +7,7 @@ macro_rules! impl_atomic_int_layout { (impl $at:ident ( $align:literal : $cfg:literal ) => $ty:ty => $val:literal) => { #[cfg(target_has_atomic_load_store = $cfg)] unsafe impl TypeLayout for core::sync::atomic::$at { - type Inhabited = crate::inhabited::Inhabited; + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), @@ -50,7 +50,7 @@ macro_rules! impl_atomic_int_ptr_sized_layout { #[cfg(target_has_atomic_load_store = "ptr")] #[cfg(target_pointer_width = $cfg)] unsafe impl TypeLayout for core::sync::atomic::$at { - type Inhabited = crate::inhabited::Inhabited; + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), @@ -92,7 +92,7 @@ macro_rules! impl_atomic_ptr_layout { #[cfg(target_has_atomic_load_store = "ptr")] #[cfg(target_pointer_width = $cfg)] unsafe impl TypeLayout for core::sync::atomic::AtomicPtr { - type Inhabited = crate::inhabited::Inhabited; + const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), diff --git a/src/impls/core/sync/mod.rs b/src/impls/core/sync/mod.rs index bba3177..e53a882 100644 --- a/src/impls/core/sync/mod.rs +++ b/src/impls/core/sync/mod.rs @@ -6,8 +6,7 @@ use crate::{ mod atomic; unsafe impl TypeLayout for core::sync::Exclusive { - type Inhabited = T::Inhabited; - + const INHABITED: crate::MaybeUninhabited = T::INHABITED; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/tuple.rs b/src/impls/core/tuple.rs index 3885ce1..778280e 100644 --- a/src/impls/core/tuple.rs +++ b/src/impls/core/tuple.rs @@ -6,7 +6,7 @@ use crate::{ macro_rules! impl_tuple_type_layout { (impl ($($a:tt => $T:ident),+)) => { unsafe impl<$($T: TypeLayout),*> TypeLayout for ($($T,)*) { - type Inhabited = crate::inhabited::all![$($T),*]; + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![$($T),*]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), diff --git a/src/inhabited.rs b/src/inhabited.rs index ce372b9..74a9efa 100644 --- a/src/inhabited.rs +++ b/src/inhabited.rs @@ -5,121 +5,7 @@ //! [uninhabited]: https://doc.rust-lang.org/reference/glossary.html#uninhabited #![allow(clippy::undocumented_unsafe_blocks)] - -/// Marker type used to specify that a type implementing -/// [`crate::TypeLayout::Inhabited`] is -/// [inhabited](https://doc.rust-lang.org/reference/glossary.html#inhabited). -pub struct Inhabited; - -unsafe impl crate::TypeLayout for Inhabited { - type Inhabited = Self; - - const TYPE_LAYOUT: crate::TypeLayoutInfo<'static> = crate::TypeLayoutInfo { - name: ::core::any::type_name::(), - size: ::core::mem::size_of::(), - alignment: ::core::mem::align_of::(), - structure: crate::TypeStructure::Struct { - repr: "", - fields: &[], - }, - }; -} - -unsafe impl crate::typeset::ComputeTypeSet for Inhabited { - type Output = crate::typeset::tset![.. @ T]; -} - -#[allow(clippy::empty_enum)] -/// Marker type used to specify that a type implementing -/// [`crate::TypeLayout::Inhabited`] is -/// [uninhabited](https://doc.rust-lang.org/reference/glossary.html#uninhabited). -pub enum Uninhabited {} - -unsafe impl crate::TypeLayout for Uninhabited { - type Inhabited = Self; - - const TYPE_LAYOUT: crate::TypeLayoutInfo<'static> = crate::TypeLayoutInfo { - name: ::core::any::type_name::(), - size: ::core::mem::size_of::(), - alignment: ::core::mem::align_of::(), - structure: crate::TypeStructure::Enum { - repr: "", - variants: &[], - }, - }; -} - -unsafe impl crate::typeset::ComputeTypeSet for Uninhabited { - type Output = crate::typeset::tset![.. @ T]; -} - -#[allow(clippy::module_name_repetitions)] -#[doc(hidden)] -pub trait ComputeInhabited: sealed::ComputeInhabited { - type Output: OutputMaybeInhabited; -} - -#[allow(clippy::module_name_repetitions)] -#[doc(hidden)] -pub trait OutputMaybeInhabited: - ComputeInhabited + crate::TypeGraphLayout + sealed::OutputMaybeInhabited -{ -} - -mod sealed { - pub trait ComputeInhabited {} - pub trait OutputMaybeInhabited {} -} - -impl sealed::ComputeInhabited for Inhabited {} -impl ComputeInhabited for Inhabited { - type Output = Self; -} -impl sealed::OutputMaybeInhabited for Inhabited {} -impl OutputMaybeInhabited for Inhabited {} - -impl sealed::ComputeInhabited for Uninhabited {} -impl ComputeInhabited for Uninhabited { - type Output = Self; -} -impl sealed::OutputMaybeInhabited for Uninhabited {} -impl OutputMaybeInhabited for Uninhabited {} - -mod logical { - use super::{sealed, ComputeInhabited, Inhabited, Uninhabited}; - - pub struct And { - _left: L, - _right: R, - } - - impl sealed::ComputeInhabited for And {} - impl ComputeInhabited for And { - default type Output = Uninhabited; - } - - impl, R: ComputeInhabited> - ComputeInhabited for And - { - type Output = Inhabited; - } - - pub struct Or { - _left: L, - _right: R, - } - - impl sealed::ComputeInhabited for Or {} - impl ComputeInhabited for Or { - default type Output = Inhabited; - } - - impl, R: ComputeInhabited> - ComputeInhabited for Or - { - type Output = Uninhabited; - } -} +#![allow(missing_docs)] // FIXME /// Helper macro to compute whether all of a list of types, all implementing /// [`crate::TypeLayout`], e.g. `[T, U, V]`, are [inhabited]. @@ -130,9 +16,9 @@ mod logical { /// /// [inhabited]: https://doc.rust-lang.org/reference/glossary.html#inhabited pub macro all { - () => { Inhabited }, + () => { $crate::MaybeUninhabited::Inhabited(()) }, ($L:ty $(, $R:ty)*) => { - ::Inhabited, all![$($R),*]> as ComputeInhabited>::Output + <$L as $crate::TypeLayout>::INHABITED.and(all![$($R),*]) }, } @@ -146,8 +32,8 @@ pub macro all { /// [inhabited]: https://doc.rust-lang.org/reference/glossary.html#inhabited /// [uninhabited]: https://doc.rust-lang.org/reference/glossary.html#uninhabited pub macro any { - () => { Uninhabited }, + () => { $crate::MaybeUninhabited::Uninhabited }, ($L:ty $(, $R:ty)*) => { - ::Inhabited, any![$($R),*]> as ComputeInhabited>::Output + <$L as $crate::TypeLayout>::INHABITED.or(any![$($R),*]) }, } diff --git a/src/lib.rs b/src/lib.rs index 342f422..49d1997 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -182,7 +182,7 @@ pub mod typeset; #[cfg_attr(feature = "serde", derive(::serde::Deserialize))] /// Optional value that exists if some other type is /// [inhabited](https://doc.rust-lang.org/reference/glossary.html#inhabited). -pub enum MaybeUninhabited { +pub enum MaybeUninhabited { /// The type is [uninhabited](https://doc.rust-lang.org/reference/glossary.html#uninhabited), /// no value. Uninhabited, @@ -198,10 +198,28 @@ impl MaybeUninhabited { /// [`inhabited::Inhabited`], [`MaybeUninhabited::Uninhabited`] /// otherwise. pub const fn new(v: T) -> Self { - if >::EQ { - Self::Inhabited(v) - } else { - Self::Uninhabited + match U::INHABITED { + MaybeUninhabited::Inhabited(()) => Self::Inhabited(v), + MaybeUninhabited::Uninhabited => Self::Uninhabited, + } + } +} + +#[allow(missing_docs)] // FIXME +impl MaybeUninhabited { + #[must_use] + pub const fn and(self, b: Self) -> Self { + match (self, b) { + (Self::Inhabited(()), Self::Inhabited(())) => Self::Inhabited(()), + _ => Self::Uninhabited, + } + } + + #[must_use] + pub const fn or(self, b: Self) -> Self { + match (self, b) { + (Self::Uninhabited, Self::Uninhabited) => Self::Uninhabited, + _ => Self::Inhabited(()), } } } @@ -239,7 +257,7 @@ impl Default for MaybeUninhabited { /// } /// /// unsafe impl TypeLayout for Foo { -/// type Inhabited = inhabited::all![u8, u16]; +/// const INHABITED: crate::MaybeUninhabited = inhabited::all![u8, u16]; /// /// const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { /// name: ::core::any::type_name::(), @@ -272,7 +290,7 @@ pub unsafe trait TypeLayout: Sized { /// [uninhabited](https://doc.rust-lang.org/reference/glossary.html#uninhabited). /// The associated type must be either [`inhabited::Inhabited`] /// or [`inhabited::Uninhabited`]. - type Inhabited: inhabited::OutputMaybeInhabited; + const INHABITED: MaybeUninhabited; /// Shallow layout of the type. const TYPE_LAYOUT: TypeLayoutInfo<'static>; diff --git a/src/typeset.rs b/src/typeset.rs index 8c8bdb8..46e9092 100644 --- a/src/typeset.rs +++ b/src/typeset.rs @@ -46,7 +46,7 @@ type Set = ::Output; /// } /// /// # unsafe impl TypeLayout for Foo { -/// # type Inhabited = inhabited::all![u8, u16]; +/// # const INHABITED: crate::MaybeUninhabited = inhabited::all![u8, u16]; /// # /// # const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { /// # name: ::core::any::type_name::(), From 68b32c8b8ffc13f97dac955dccb5f432403a1e5b Mon Sep 17 00:00:00 2001 From: Juniper Tyree <50025784+juntyr@users.noreply.github.com> Date: Thu, 3 Oct 2024 10:52:05 +0000 Subject: [PATCH 2/7] Further sketch what a simplified inhabited would look like --- .cargo/config.toml | 2 -- .gitpod.Dockerfile | 7 ------ .gitpod.yml | 21 ----------------- .vscode/settings.json | 6 ----- README.md | 5 +---- const-type-layout-derive/src/lib.rs | 17 ++++++-------- src/inhabited.rs | 35 ++++++++++++++++++++--------- src/lib.rs | 21 ++++++++--------- 8 files changed, 44 insertions(+), 70 deletions(-) delete mode 100644 .cargo/config.toml delete mode 100644 .gitpod.Dockerfile delete mode 100644 .gitpod.yml delete mode 100644 .vscode/settings.json diff --git a/.cargo/config.toml b/.cargo/config.toml deleted file mode 100644 index c1f0256..0000000 --- a/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[alias] -reap-clippy = "reaper cargo clippy" diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile deleted file mode 100644 index 557e63d..0000000 --- a/.gitpod.Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM gitpod/workspace-full - -USER gitpod - -ENV DEBIAN_FRONTEND=noninteractive - -RUN cargo install cargo-reaper --git https://github.com/juntyr/grim-reaper -f diff --git a/.gitpod.yml b/.gitpod.yml deleted file mode 100644 index 192e2e0..0000000 --- a/.gitpod.yml +++ /dev/null @@ -1,21 +0,0 @@ -image: - file: .gitpod.Dockerfile - -vscode: - extensions: - - bungcip.better-toml - - serayuzgur.crates - - matklad.rust-analyzer - -github: - prebuilds: - # enable for the main/default branch (defaults to true) - master: true - # enable for all branches in this repo (defaults to false) - branches: true - # enable for pull requests coming from this repo (defaults to true) - pullRequests: true - # add a check to pull requests (defaults to true) - addCheck: true - # add a "Review in Gitpod" button as a comment to pull requests (defaults to false) - addComment: true diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index ed551a3..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "crates.localCargoIndexBranch": "origin/HEAD", - "rust-analyzer.procMacro.enable": false, - "rust-analyzer.updates.askBeforeDownload": false, - "rust-analyzer.checkOnSave.command": "reap-clippy", -} diff --git a/README.md b/README.md index b973d8c..8919a6e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![CI Status]][workflow] [![MSRV]][repo] [![Latest Version]][crates.io] [![Rust Doc Crate]][docs.rs] [![Rust Doc Main]][docs] [![License Status]][fossa] [![Code Coverage]][codecov] [![Gitpod Ready-to-Code]][gitpod] +[![CI Status]][workflow] [![MSRV]][repo] [![Latest Version]][crates.io] [![Rust Doc Crate]][docs.rs] [![Rust Doc Main]][docs] [![License Status]][fossa] [![Code Coverage]][codecov] [CI Status]: https://img.shields.io/github/actions/workflow/status/juntyr/const-type-layout/ci.yml?branch=main [workflow]: https://github.com/juntyr/const-type-layout/actions/workflows/ci.yml?query=branch%3Amain @@ -21,9 +21,6 @@ [Code Coverage]: https://img.shields.io/codecov/c/github/juntyr/const-type-layout?token=J39WVBIMZX [codecov]: https://codecov.io/gh/juntyr/const-type-layout -[Gitpod Ready-to-Code]: https://img.shields.io/badge/Gitpod-ready-blue?logo=gitpod -[gitpod]: https://gitpod.io/#https://github.com/juntyr/const-type-layout - `const-type-layout` is a type layout comparison aid, providing a `#[derive]`able `TypeLayout` trait that reports: - The type's name, size, and minimum alignment diff --git a/const-type-layout-derive/src/lib.rs b/const-type-layout-derive/src/lib.rs index bae5be9..d1bbba7 100644 --- a/const-type-layout-derive/src/lib.rs +++ b/const-type-layout-derive/src/lib.rs @@ -1,7 +1,6 @@ //! [![CI Status]][workflow] [![MSRV]][repo] [![Latest Version]][crates.io] //! [![Rust Doc Crate]][docs.rs] [![Rust Doc Main]][docs] //! [![License Status]][fossa] [![Code Coverage]][codecov] -//! [![Gitpod Ready-to-Code]][gitpod] //! //! [CI Status]: https://img.shields.io/github/actions/workflow/status/juntyr/const-type-layout/ci.yml?branch=main //! [workflow]: https://github.com/juntyr/const-type-layout/actions/workflows/ci.yml?query=branch%3Amain @@ -24,9 +23,6 @@ //! [Code Coverage]: https://img.shields.io/codecov/c/github/juntyr/const-type-layout?token=J39WVBIMZX //! [codecov]: https://codecov.io/gh/juntyr/const-type-layout //! -//! [Gitpod Ready-to-Code]: https://img.shields.io/badge/Gitpod-ready-blue?logo=gitpod -//! [gitpod]: https://gitpod.io/#https://github.com/juntyr/const-type-layout -//! //! `const-type-layout-derive` provides the [`#[derive(TypeLayout)`](TypeLayout) //! implementation for the //! [`const_type_layout::TypeLayout`](https://docs.rs/const-type-layout/0.3/const_type_layout/trait.TypeLayout.html) @@ -113,7 +109,7 @@ pub fn derive_type_layout(input: TokenStream) -> TokenStream { unsafe impl #type_layout_impl_generics #crate_path::TypeLayout for #ty_name #type_layout_ty_generics #type_layout_where_clause { - const INHABITED: #crate_path::inhabited::Inhabited = #inhabited; + const INHABITED: #crate_path::MaybeUninhabited = #inhabited; const TYPE_LAYOUT: #crate_path::TypeLayoutInfo<'static> = { #crate_path::TypeLayoutInfo { @@ -554,11 +550,11 @@ fn quote_enum_variants( quote! { #crate_path::inhabited::all![#(#field_tys),*] } }, - syn::Fields::Unit => quote! { #crate_path::inhabited::Inhabited }, + syn::Fields::Unit => quote! { #crate_path::inhabited::all![] }, }; let discriminant = quote! { - #crate_path::MaybeUninhabited::new::<#variant_inhabited>( + #variant_inhabited.map( #crate_path::Discriminant::new::(#discriminant) ) }; @@ -663,7 +659,7 @@ fn inhabited_for_type(crate_path: &syn::Path, data: &syn::Data) -> proc_macro2:: | syn::Fields::Unnamed(syn::FieldsUnnamed { unnamed: fields, .. }) => fields, - syn::Fields::Unit => return quote! { #crate_path::inhabited::Inhabited }, + syn::Fields::Unit => return quote! { #crate_path::inhabited::all![] }, }; let field_tys = fields.iter().map(|syn::Field { ty, .. }| ty); @@ -678,7 +674,7 @@ fn inhabited_for_type(crate_path: &syn::Path, data: &syn::Data) -> proc_macro2:: | syn::Fields::Unnamed(syn::FieldsUnnamed { unnamed: fields, .. }) => fields, - syn::Fields::Unit => return quote! { #crate_path::inhabited::Inhabited }, + syn::Fields::Unit => return quote! { #crate_path::inhabited::all![] }, }; let field_tys = fields.iter().map(|syn::Field { ty, .. }| ty); @@ -688,7 +684,8 @@ fn inhabited_for_type(crate_path: &syn::Path, data: &syn::Data) -> proc_macro2:: // Enums are inhabited if they have at least one inhabited variant quote! { - #crate_path::inhabited::any![#(#variants_inhabited),*] + #crate_path::inhabited::any![] + #(.or(#variants_inhabited))* } }, syn::Data::Union(syn::DataUnion { diff --git a/src/inhabited.rs b/src/inhabited.rs index 74a9efa..3da3cd4 100644 --- a/src/inhabited.rs +++ b/src/inhabited.rs @@ -4,8 +4,14 @@ //! [inhabited]: https://doc.rust-lang.org/reference/glossary.html#inhabited //! [uninhabited]: https://doc.rust-lang.org/reference/glossary.html#uninhabited -#![allow(clippy::undocumented_unsafe_blocks)] -#![allow(missing_docs)] // FIXME +#[allow(non_upper_case_globals)] +/// Marker used to specify that a type implementing [`crate::TypeLayout`] is +/// [inhabited](https://doc.rust-lang.org/reference/glossary.html#inhabited). +pub const Inhabited: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + +/// Marker used to specify that a type implementing [`crate::TypeLayout`] is +/// [uninhabited](https://doc.rust-lang.org/reference/glossary.html#uninhabited). +pub use crate::MaybeUninhabited::Uninhabited; /// Helper macro to compute whether all of a list of types, all implementing /// [`crate::TypeLayout`], e.g. `[T, U, V]`, are [inhabited]. @@ -15,11 +21,14 @@ /// [`Inhabited`] or [`Uninhabited`]. /// /// [inhabited]: https://doc.rust-lang.org/reference/glossary.html#inhabited -pub macro all { - () => { $crate::MaybeUninhabited::Inhabited(()) }, +#[macro_export] +macro_rules! all { + () => { $crate::inhabited::Inhabited }; ($L:ty $(, $R:ty)*) => { - <$L as $crate::TypeLayout>::INHABITED.and(all![$($R),*]) - }, + <$L as $crate::TypeLayout>::INHABITED.and( + $crate::inhabited::all![$($R),*] + ) + }; } /// Helper macro to compute whether any of a list of types, all implementing @@ -31,9 +40,15 @@ pub macro all { /// /// [inhabited]: https://doc.rust-lang.org/reference/glossary.html#inhabited /// [uninhabited]: https://doc.rust-lang.org/reference/glossary.html#uninhabited -pub macro any { - () => { $crate::MaybeUninhabited::Uninhabited }, +#[macro_export] +macro_rules! any { + () => { $crate::inhabited::Uninhabited }; ($L:ty $(, $R:ty)*) => { - <$L as $crate::TypeLayout>::INHABITED.or(any![$($R),*]) - }, + <$L as $crate::TypeLayout>::INHABITED.or( + $crate::inhabited::any![$($R),*] + ) + }; } + +pub use all; +pub use any; diff --git a/src/lib.rs b/src/lib.rs index 49d1997..9f577a4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ //! [![CI Status]][workflow] [![MSRV]][repo] [![Latest Version]][crates.io] //! [![Rust Doc Crate]][docs.rs] [![Rust Doc Main]][docs] //! [![License Status]][fossa] [![Code Coverage]][codecov] -//! [![Gitpod Ready-to-Code]][gitpod] //! //! [CI Status]: https://img.shields.io/github/actions/workflow/status/juntyr/const-type-layout/ci.yml?branch=main //! [workflow]: https://github.com/juntyr/const-type-layout/actions/workflows/ci.yml?query=branch%3Amain @@ -24,9 +23,6 @@ //! [Code Coverage]: https://img.shields.io/codecov/c/github/juntyr/const-type-layout?token=J39WVBIMZX //! [codecov]: https://codecov.io/gh/juntyr/const-type-layout //! -//! [Gitpod Ready-to-Code]: https://img.shields.io/badge/Gitpod-ready-blue?logo=gitpod -//! [gitpod]: https://gitpod.io/#https://github.com/juntyr/const-type-layout -//! //! `const-type-layout` is a type layout comparison aid, providing a //! [`#[derive]`](const_type_layout_derive::TypeLayout)able [`TypeLayout`] trait //! that provides a const [`TypeLayoutInfo`] struct containing: @@ -144,7 +140,7 @@ r#"TypeLayoutInfo { #![no_std] #![feature(const_type_name)] #![cfg_attr(not(version("1.83")), feature(const_mut_refs))] -#![feature(cfg_target_has_atomic)] +#![feature(cfg_target_has_atomic)] // https://github.com/rust-lang/rust/issues/94039 #![feature(decl_macro)] #![feature(never_type)] #![feature(discriminant_kind)] @@ -198,15 +194,20 @@ impl MaybeUninhabited { /// [`inhabited::Inhabited`], [`MaybeUninhabited::Uninhabited`] /// otherwise. pub const fn new(v: T) -> Self { - match U::INHABITED { - MaybeUninhabited::Inhabited(()) => Self::Inhabited(v), - MaybeUninhabited::Uninhabited => Self::Uninhabited, - } + U::INHABITED.map(v) } } #[allow(missing_docs)] // FIXME impl MaybeUninhabited { + #[must_use] + pub const fn map(self, v: T) -> MaybeUninhabited { + match self { + Self::Inhabited(()) => MaybeUninhabited::Inhabited(v), + Self::Uninhabited => MaybeUninhabited::Uninhabited, + } + } + #[must_use] pub const fn and(self, b: Self) -> Self { match (self, b) { @@ -285,7 +286,7 @@ impl Default for MaybeUninhabited { /// Note that if you implement [`TypeLayout`], you should also implement /// [`typeset::ComputeTypeSet`] for it. pub unsafe trait TypeLayout: Sized { - /// Marker type for whether the type is + /// Marker for whether the type is /// [inhabited](https://doc.rust-lang.org/reference/glossary.html#inhabited) or /// [uninhabited](https://doc.rust-lang.org/reference/glossary.html#uninhabited). /// The associated type must be either [`inhabited::Inhabited`] From f867d85f78746c6c2a06529c374387be3688c0c1 Mon Sep 17 00:00:00 2001 From: Juniper Tyree <50025784+juntyr@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:59:13 +0000 Subject: [PATCH 3/7] Further cleanup --- const-type-layout-derive/src/lib.rs | 5 +-- src/inhabited.rs | 55 +++++++++++++++++++---------- src/lib.rs | 24 +++++++++---- 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/const-type-layout-derive/src/lib.rs b/const-type-layout-derive/src/lib.rs index d1bbba7..2a7b531 100644 --- a/const-type-layout-derive/src/lib.rs +++ b/const-type-layout-derive/src/lib.rs @@ -683,10 +683,7 @@ fn inhabited_for_type(crate_path: &syn::Path, data: &syn::Data) -> proc_macro2:: }); // Enums are inhabited if they have at least one inhabited variant - quote! { - #crate_path::inhabited::any![] - #(.or(#variants_inhabited))* - } + quote! { #crate_path::inhabited::any![#({ #variants_inhabited }),*] } }, syn::Data::Union(syn::DataUnion { fields: syn::FieldsNamed { named: fields, .. }, diff --git a/src/inhabited.rs b/src/inhabited.rs index 3da3cd4..27669c3 100644 --- a/src/inhabited.rs +++ b/src/inhabited.rs @@ -4,51 +4,68 @@ //! [inhabited]: https://doc.rust-lang.org/reference/glossary.html#inhabited //! [uninhabited]: https://doc.rust-lang.org/reference/glossary.html#uninhabited -#[allow(non_upper_case_globals)] -/// Marker used to specify that a type implementing [`crate::TypeLayout`] is -/// [inhabited](https://doc.rust-lang.org/reference/glossary.html#inhabited). -pub const Inhabited: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); - -/// Marker used to specify that a type implementing [`crate::TypeLayout`] is -/// [uninhabited](https://doc.rust-lang.org/reference/glossary.html#uninhabited). -pub use crate::MaybeUninhabited::Uninhabited; - -/// Helper macro to compute whether all of a list of types, all implementing -/// [`crate::TypeLayout`], e.g. `[T, U, V]`, are [inhabited]. +/// Helper macro to compute whether +/// +/// - all of a list of types, all implementing [`crate::TypeLayout`], e.g. `[T, +/// U, V]`, +/// - all of a list of braced expressions of type [`crate::MaybeUninhabited`], +/// e.g. `[{ all![] }, { any![] }, { all![] }]`, +/// +/// are [inhabited]. /// /// For instance, a struct is inhabited iff all of its fields are inhabited. /// The empty list of types is inhabited. This macro resolves into either -/// [`Inhabited`] or [`Uninhabited`]. +/// [`crate::MaybeUninhabited::Inhabited`] or +/// [`crate::MaybeUninhabited::Uninhabited`]. /// /// [inhabited]: https://doc.rust-lang.org/reference/glossary.html#inhabited #[macro_export] +#[doc(hidden)] macro_rules! all { - () => { $crate::inhabited::Inhabited }; + () => { $crate::MaybeUninhabited::Inhabited(()) }; ($L:ty $(, $R:ty)*) => { <$L as $crate::TypeLayout>::INHABITED.and( $crate::inhabited::all![$($R),*] ) }; + ({ $L:expr } $(, { $R:expr })*) => { + $crate::MaybeUninhabited::and( + $L, $crate::inhabited::all![$({ $R }),*] + ) + }; } -/// Helper macro to compute whether any of a list of types, all implementing -/// [`crate::TypeLayout`], e.g. `[T, U, V]`, is [inhabited]. +/// Helper macro to compute whether +/// +/// - any of a list of types, all implementing [`crate::TypeLayout`], e.g. `[T, +/// U, V]`, +/// - any of a list of braced expressions of type [`crate::MaybeUninhabited`], +/// e.g. `[{ all![] }, { any![] }, { all![] }]`, +/// +/// is [inhabited]. /// /// For instance, an enum is inhabited iff any of its variants is inhabited. /// The empty list of types is [uninhabited]. This macro resolves into either -/// [`Inhabited`] or [`Uninhabited`]. +/// [`crate::MaybeUninhabited::Inhabited`] or +/// [`crate::MaybeUninhabited::Uninhabited`]. /// /// [inhabited]: https://doc.rust-lang.org/reference/glossary.html#inhabited /// [uninhabited]: https://doc.rust-lang.org/reference/glossary.html#uninhabited #[macro_export] +#[doc(hidden)] macro_rules! any { - () => { $crate::inhabited::Uninhabited }; + () => { $crate::MaybeUninhabited::Uninhabited }; ($L:ty $(, $R:ty)*) => { <$L as $crate::TypeLayout>::INHABITED.or( $crate::inhabited::any![$($R),*] ) }; + ({ $L:expr } $(, { $R:expr })*) => { + $crate::MaybeUninhabited::or( + $L, $crate::inhabited::any![$({ $R }),*] + ) + }; } -pub use all; -pub use any; +#[doc(inline)] +pub use {all, any}; diff --git a/src/lib.rs b/src/lib.rs index 9f577a4..6e6002f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -190,17 +190,19 @@ pub enum MaybeUninhabited { impl MaybeUninhabited { #[must_use] /// Construct [`MaybeUninhabited::Inhabited`] iff [`::Inhabited`](TypeLayout::Inhabited) is - /// [`inhabited::Inhabited`], [`MaybeUninhabited::Uninhabited`] + /// TypeLayout>::INHABITED`][`TypeLayout::INHABITED`] is + /// [`MaybeUninhabited::Inhabited`], [`MaybeUninhabited::Uninhabited`] /// otherwise. pub const fn new(v: T) -> Self { U::INHABITED.map(v) } } -#[allow(missing_docs)] // FIXME impl MaybeUninhabited { #[must_use] + /// Maps a [`MaybeUninhabited::Inhabited`] to a + /// [`MaybeUninhabited::Inhabited`] with the value `v` or returns + /// [`MaybeUninhabited::Uninhabited`]. pub const fn map(self, v: T) -> MaybeUninhabited { match self { Self::Inhabited(()) => MaybeUninhabited::Inhabited(v), @@ -209,14 +211,24 @@ impl MaybeUninhabited { } #[must_use] - pub const fn and(self, b: Self) -> Self { - match (self, b) { + /// Returns the logical and between `self` and `other`. + /// + /// The result is [`MaybeUninhabited::Inhabited`] iff both `self` and + /// `other` are [`MaybeUninhabited::Inhabited`], + /// [`MaybeUninhabited::Uninhabited`] otherwise. + pub const fn and(self, other: Self) -> Self { + match (self, other) { (Self::Inhabited(()), Self::Inhabited(())) => Self::Inhabited(()), _ => Self::Uninhabited, } } #[must_use] + /// Returns the or and between `self` and `other`. + /// + /// The result is [`MaybeUninhabited::Uninhabited`] iff both `self` and + /// `other` are [`MaybeUninhabited::Uninhabited`], + /// [`MaybeUninhabited::Inhabited`] otherwise. pub const fn or(self, b: Self) -> Self { match (self, b) { (Self::Uninhabited, Self::Uninhabited) => Self::Uninhabited, @@ -289,8 +301,6 @@ pub unsafe trait TypeLayout: Sized { /// Marker for whether the type is /// [inhabited](https://doc.rust-lang.org/reference/glossary.html#inhabited) or /// [uninhabited](https://doc.rust-lang.org/reference/glossary.html#uninhabited). - /// The associated type must be either [`inhabited::Inhabited`] - /// or [`inhabited::Uninhabited`]. const INHABITED: MaybeUninhabited; /// Shallow layout of the type. From d5c049deea1b6beed129a87bdded032011a85bc4 Mon Sep 17 00:00:00 2001 From: Juniper Tyree <50025784+juntyr@users.noreply.github.com> Date: Thu, 3 Oct 2024 18:06:24 +0000 Subject: [PATCH 4/7] Fix tests --- src/lib.rs | 11 +++-------- src/typeset.rs | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6e6002f..319107f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,8 +47,6 @@ on non-`#[repr(C)]` types, but their layout is unpredictable. ```rust # #![feature(const_type_name)] -# #![feature(offset_of)] -# #![feature(offset_of_enum)] use const_type_layout::TypeLayout; #[derive(TypeLayout)] @@ -61,7 +59,7 @@ struct Foo { assert_eq!( format!("{:#?}", Foo::TYPE_LAYOUT), r#"TypeLayoutInfo { - name: "rust_out::main::_doctest_main_src_lib_rs_49_0::Foo", + name: "rust_out::main::_doctest_main_src_lib_rs_45_0::Foo", size: 8, alignment: 4, structure: Struct { @@ -92,8 +90,6 @@ FFI scenarios: ```rust # #![feature(const_type_name)] -# #![feature(offset_of)] -# #![feature(offset_of_enum)] use const_type_layout::TypeLayout; #[derive(TypeLayout)] @@ -105,7 +101,7 @@ struct OverAligned { assert_eq!( format!("{:#?}", OverAligned::TYPE_LAYOUT), r#"TypeLayoutInfo { - name: "rust_out::main::_doctest_main_src_lib_rs_94_0::OverAligned", + name: "rust_out::main::_doctest_main_src_lib_rs_88_0::OverAligned", size: 128, alignment: 128, structure: Struct { @@ -258,7 +254,6 @@ impl Default for MaybeUninhabited { /// /// ```rust /// # #![feature(const_type_name)] -/// # #![feature(offset_of)] /// # use const_type_layout::{ /// # Field, MaybeUninhabited, TypeLayout, TypeLayoutInfo, TypeStructure, /// # }; @@ -270,7 +265,7 @@ impl Default for MaybeUninhabited { /// } /// /// unsafe impl TypeLayout for Foo { -/// const INHABITED: crate::MaybeUninhabited = inhabited::all![u8, u16]; +/// const INHABITED: MaybeUninhabited = inhabited::all![u8, u16]; /// /// const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { /// name: ::core::any::type_name::(), diff --git a/src/typeset.rs b/src/typeset.rs index 46e9092..5c4b9e6 100644 --- a/src/typeset.rs +++ b/src/typeset.rs @@ -46,7 +46,7 @@ type Set = ::Output; /// } /// /// # unsafe impl TypeLayout for Foo { -/// # const INHABITED: crate::MaybeUninhabited = inhabited::all![u8, u16]; +/// # const INHABITED: MaybeUninhabited = inhabited::all![u8, u16]; /// # /// # const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { /// # name: ::core::any::type_name::(), From bfa509c04d008ab29c66c7e8a73d82aeccafa782 Mon Sep 17 00:00:00 2001 From: Juniper Tyree <50025784+juntyr@users.noreply.github.com> Date: Thu, 3 Oct 2024 18:20:39 +0000 Subject: [PATCH 5/7] Cleanup impls --- src/impls/core/cmp.rs | 2 +- src/impls/core/convert.rs | 2 +- src/impls/core/ffi.rs | 2 +- src/impls/core/fn.rs | 4 ++-- src/impls/core/marker.rs | 4 ++-- src/impls/core/mem.rs | 4 ++-- src/impls/core/num.rs | 2 +- src/impls/core/ops.rs | 4 ++-- src/impls/core/option.rs | 2 +- src/impls/core/primitive.rs | 4 ++-- src/impls/core/ptr.rs | 6 +++--- src/impls/core/ref.rs | 4 ++-- src/impls/core/sync/atomic.rs | 6 +++--- src/inhabited.rs | 4 ++++ 14 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/impls/core/cmp.rs b/src/impls/core/cmp.rs index e84d378..ed69637 100644 --- a/src/impls/core/cmp.rs +++ b/src/impls/core/cmp.rs @@ -25,7 +25,7 @@ unsafe impl ComputeTypeSet for core::cmp::Reverse { } unsafe impl TypeLayout for core::cmp::Ordering { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/convert.rs b/src/impls/core/convert.rs index f29ce70..b355106 100644 --- a/src/impls/core/convert.rs +++ b/src/impls/core/convert.rs @@ -4,7 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for core::convert::Infallible { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/ffi.rs b/src/impls/core/ffi.rs index 8ba9297..1c09ddf 100644 --- a/src/impls/core/ffi.rs +++ b/src/impls/core/ffi.rs @@ -4,7 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for core::ffi::c_void { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/fn.rs b/src/impls/core/fn.rs index 2bf412c..cf5890a 100644 --- a/src/impls/core/fn.rs +++ b/src/impls/core/fn.rs @@ -20,7 +20,7 @@ macro_rules! impl_fn_pointer_type_layout { }; (impl extern $abi:literal fn($($T:ident),*) -> $R:ident, $ty:ty, $demo:item) => { unsafe impl<$R: TypeLayout, $($T: TypeLayout),*> TypeLayout for $ty { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), @@ -63,7 +63,7 @@ macro_rules! impl_variadic_extern_fn_pointer_type_layout { unsafe impl<$R: TypeLayout, $($T: TypeLayout),*> TypeLayout for unsafe extern $abi fn($($T),*, ...) -> $R { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), diff --git a/src/impls/core/marker.rs b/src/impls/core/marker.rs index 6b8090e..05b1bd9 100644 --- a/src/impls/core/marker.rs +++ b/src/impls/core/marker.rs @@ -4,7 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for core::marker::PhantomData { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -21,7 +21,7 @@ unsafe impl ComputeTypeSet for core::marker::PhantomData { } unsafe impl TypeLayout for core::marker::PhantomPinned { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/mem.rs b/src/impls/core/mem.rs index 3df1b80..da41658 100644 --- a/src/impls/core/mem.rs +++ b/src/impls/core/mem.rs @@ -25,7 +25,7 @@ unsafe impl ComputeTypeSet for core::mem::ManuallyDrop { } unsafe impl TypeLayout for core::mem::MaybeUninit { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -53,7 +53,7 @@ unsafe impl ComputeTypeSet for core::mem::MaybeUninit { } unsafe impl TypeLayout for core::mem::Discriminant { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/num.rs b/src/impls/core/num.rs index 9e9fd8e..b6ca5d1 100644 --- a/src/impls/core/num.rs +++ b/src/impls/core/num.rs @@ -6,7 +6,7 @@ use crate::{ macro_rules! impl_nonzero_type_layout { (impl $nz:ident => $ty:ty) => { unsafe impl TypeLayout for core::num::$nz { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), diff --git a/src/impls/core/ops.rs b/src/impls/core/ops.rs index b5f031c..c361139 100644 --- a/src/impls/core/ops.rs +++ b/src/impls/core/ops.rs @@ -53,7 +53,7 @@ unsafe impl ComputeTypeSet for core::ops::RangeFrom { } unsafe impl TypeLayout for core::ops::RangeFull { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -112,7 +112,7 @@ unsafe impl ComputeTypeSet for core::ops::RangeToInclusive< } unsafe impl TypeLayout for core::ops::Bound { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/option.rs b/src/impls/core/option.rs index 37a755a..87fa8cf 100644 --- a/src/impls/core/option.rs +++ b/src/impls/core/option.rs @@ -4,7 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for core::option::Option { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/primitive.rs b/src/impls/core/primitive.rs index ec0bf2f..00d0d39 100644 --- a/src/impls/core/primitive.rs +++ b/src/impls/core/primitive.rs @@ -6,7 +6,7 @@ use crate::{ macro_rules! impl_primitive_type_layout { (impl $ty:ty => $val:expr) => { unsafe impl TypeLayout for $ty { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), @@ -33,7 +33,7 @@ impl_primitive_type_layout! { } unsafe impl TypeLayout for ! { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/ptr.rs b/src/impls/core/ptr.rs index 06d464e..1bf5a79 100644 --- a/src/impls/core/ptr.rs +++ b/src/impls/core/ptr.rs @@ -4,7 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for *const T { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -18,7 +18,7 @@ unsafe impl ComputeTypeSet for *const T { } unsafe impl TypeLayout for *mut T { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -32,7 +32,7 @@ unsafe impl ComputeTypeSet for *mut T { } unsafe impl TypeLayout for core::ptr::NonNull { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/ref.rs b/src/impls/core/ref.rs index f900c2c..8087752 100644 --- a/src/impls/core/ref.rs +++ b/src/impls/core/ref.rs @@ -4,7 +4,7 @@ use crate::{ }; unsafe impl<'a, T: TypeLayout + 'a> TypeLayout for &'a T { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), @@ -18,7 +18,7 @@ unsafe impl<'a, T: ComputeTypeSet + 'a> ComputeTypeSet for &'a T { } unsafe impl<'a, T: TypeLayout + 'a> TypeLayout for &'a mut T { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), diff --git a/src/impls/core/sync/atomic.rs b/src/impls/core/sync/atomic.rs index 8055ac8..8f2d681 100644 --- a/src/impls/core/sync/atomic.rs +++ b/src/impls/core/sync/atomic.rs @@ -7,7 +7,7 @@ macro_rules! impl_atomic_int_layout { (impl $at:ident ( $align:literal : $cfg:literal ) => $ty:ty => $val:literal) => { #[cfg(target_has_atomic_load_store = $cfg)] unsafe impl TypeLayout for core::sync::atomic::$at { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), @@ -50,7 +50,7 @@ macro_rules! impl_atomic_int_ptr_sized_layout { #[cfg(target_has_atomic_load_store = "ptr")] #[cfg(target_pointer_width = $cfg)] unsafe impl TypeLayout for core::sync::atomic::$at { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), @@ -92,7 +92,7 @@ macro_rules! impl_atomic_ptr_layout { #[cfg(target_has_atomic_load_store = "ptr")] #[cfg(target_pointer_width = $cfg)] unsafe impl TypeLayout for core::sync::atomic::AtomicPtr { - const INHABITED: crate::MaybeUninhabited = crate::MaybeUninhabited::Inhabited(()); + const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), diff --git a/src/inhabited.rs b/src/inhabited.rs index 27669c3..1f2a28c 100644 --- a/src/inhabited.rs +++ b/src/inhabited.rs @@ -13,6 +13,8 @@ /// /// are [inhabited]. /// +/// `all![]` resolves to [`crate::MaybeUninhabited::Inhabited`]. +/// /// For instance, a struct is inhabited iff all of its fields are inhabited. /// The empty list of types is inhabited. This macro resolves into either /// [`crate::MaybeUninhabited::Inhabited`] or @@ -44,6 +46,8 @@ macro_rules! all { /// /// is [inhabited]. /// +/// `any![]` resolves to [`crate::MaybeUninhabited::Uninhabited`]. +/// /// For instance, an enum is inhabited iff any of its variants is inhabited. /// The empty list of types is [uninhabited]. This macro resolves into either /// [`crate::MaybeUninhabited::Inhabited`] or From 0b1f054a2032ced8d546aea8c7c86c5873d42d1b Mon Sep 17 00:00:00 2001 From: Juniper Tyree <50025784+juntyr@users.noreply.github.com> Date: Thu, 3 Oct 2024 18:22:17 +0000 Subject: [PATCH 6/7] Fix Infallible uninhabited --- src/impls/core/convert.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/impls/core/convert.rs b/src/impls/core/convert.rs index b355106..1897d92 100644 --- a/src/impls/core/convert.rs +++ b/src/impls/core/convert.rs @@ -4,7 +4,7 @@ use crate::{ }; unsafe impl TypeLayout for core::convert::Infallible { - const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; + const INHABITED: crate::MaybeUninhabited = crate::inhabited::any![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(), From d23f4e2bf6e21d0d7580af3f01400631a7393aa3 Mon Sep 17 00:00:00 2001 From: Juniper Tyree <50025784+juntyr@users.noreply.github.com> Date: Thu, 3 Oct 2024 18:23:58 +0000 Subject: [PATCH 7/7] Fix never uninhabited --- src/impls/core/primitive.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/impls/core/primitive.rs b/src/impls/core/primitive.rs index 00d0d39..7c99c7e 100644 --- a/src/impls/core/primitive.rs +++ b/src/impls/core/primitive.rs @@ -33,7 +33,7 @@ impl_primitive_type_layout! { } unsafe impl TypeLayout for ! { - const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![]; + const INHABITED: crate::MaybeUninhabited = crate::inhabited::any![]; const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo { name: ::core::any::type_name::(), size: ::core::mem::size_of::(),