Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .cargo/config.toml

This file was deleted.

7 changes: 0 additions & 7 deletions .gitpod.Dockerfile

This file was deleted.

21 changes: 0 additions & 21 deletions .gitpod.yml

This file was deleted.

6 changes: 0 additions & 6 deletions .vscode/settings.json

This file was deleted.

5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
18 changes: 6 additions & 12 deletions const-type-layout-derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
{
type Inhabited = #inhabited;
const INHABITED: #crate_path::MaybeUninhabited = #inhabited;

const TYPE_LAYOUT: #crate_path::TypeLayoutInfo<'static> = {
#crate_path::TypeLayoutInfo {
Expand Down Expand Up @@ -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::<Self>(#discriminant)
)
};
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -687,9 +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![#(#variants_inhabited),*]
}
quote! { #crate_path::inhabited::any![#({ #variants_inhabited }),*] }
},
syn::Data::Union(syn::DataUnion {
fields: syn::FieldsNamed { named: fields, .. },
Expand Down
3 changes: 1 addition & 2 deletions src/impls/core/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use crate::{
};

unsafe impl<T: TypeLayout, const N: usize> 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::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand Down
12 changes: 4 additions & 8 deletions src/impls/core/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use crate::{
};

unsafe impl<T: TypeLayout> TypeLayout for core::cell::UnsafeCell<T> {
type Inhabited = T::Inhabited;

const INHABITED: crate::MaybeUninhabited = T::INHABITED;
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand All @@ -26,8 +25,7 @@ unsafe impl<T: ComputeTypeSet> ComputeTypeSet for core::cell::UnsafeCell<T> {
}

unsafe impl<T: TypeLayout> TypeLayout for core::cell::Cell<T> {
type Inhabited = T::Inhabited;

const INHABITED: crate::MaybeUninhabited = T::INHABITED;
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand All @@ -48,8 +46,7 @@ unsafe impl<T: ComputeTypeSet> ComputeTypeSet for core::cell::Cell<T> {
}

unsafe impl<T: TypeLayout> TypeLayout for core::cell::SyncUnsafeCell<T> {
type Inhabited = T::Inhabited;

const INHABITED: crate::MaybeUninhabited = T::INHABITED;
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand All @@ -70,8 +67,7 @@ unsafe impl<T: ComputeTypeSet> ComputeTypeSet for core::cell::SyncUnsafeCell<T>
}

unsafe impl<T: TypeLayout> TypeLayout for core::cell::OnceCell<T> {
type Inhabited = T::Inhabited;

const INHABITED: crate::MaybeUninhabited = T::INHABITED;
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand Down
6 changes: 2 additions & 4 deletions src/impls/core/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use crate::{
};

unsafe impl<T: TypeLayout> TypeLayout for core::cmp::Reverse<T> {
type Inhabited = T::Inhabited;

const INHABITED: crate::MaybeUninhabited = T::INHABITED;
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand All @@ -26,8 +25,7 @@ unsafe impl<T: ComputeTypeSet> ComputeTypeSet for core::cmp::Reverse<T> {
}

unsafe impl TypeLayout for core::cmp::Ordering {
type Inhabited = crate::inhabited::Inhabited;

const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![];
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand Down
3 changes: 1 addition & 2 deletions src/impls/core/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use crate::{
};

unsafe impl TypeLayout for core::convert::Infallible {
type Inhabited = crate::inhabited::Uninhabited;

const INHABITED: crate::MaybeUninhabited = crate::inhabited::any![];
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand Down
3 changes: 1 addition & 2 deletions src/impls/core/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use crate::{
};

unsafe impl TypeLayout for core::ffi::c_void {
type Inhabited = crate::inhabited::Inhabited;

const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![];
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand Down
4 changes: 2 additions & 2 deletions src/impls/core/fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::inhabited::all![];

const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
Expand Down Expand Up @@ -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::inhabited::all![];

const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
Expand Down
6 changes: 2 additions & 4 deletions src/impls/core/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use crate::{
};

unsafe impl<T> TypeLayout for core::marker::PhantomData<T> {
type Inhabited = crate::inhabited::Inhabited;

const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![];
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand All @@ -22,8 +21,7 @@ unsafe impl<T> ComputeTypeSet for core::marker::PhantomData<T> {
}

unsafe impl TypeLayout for core::marker::PhantomPinned {
type Inhabited = crate::inhabited::Inhabited;

const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![];
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand Down
9 changes: 3 additions & 6 deletions src/impls/core/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use crate::{
};

unsafe impl<T: TypeLayout> TypeLayout for core::mem::ManuallyDrop<T> {
type Inhabited = T::Inhabited;

const INHABITED: crate::MaybeUninhabited = T::INHABITED;
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand All @@ -26,8 +25,7 @@ unsafe impl<T: ComputeTypeSet> ComputeTypeSet for core::mem::ManuallyDrop<T> {
}

unsafe impl<T: TypeLayout> TypeLayout for core::mem::MaybeUninit<T> {
type Inhabited = crate::inhabited::Inhabited;

const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![];
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand Down Expand Up @@ -55,8 +53,7 @@ unsafe impl<T: ComputeTypeSet> ComputeTypeSet for core::mem::MaybeUninit<T> {
}

unsafe impl<T> TypeLayout for core::mem::Discriminant<T> {
type Inhabited = crate::inhabited::Inhabited;

const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![];
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand Down
8 changes: 3 additions & 5 deletions src/impls/core/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::inhabited::all![];

const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
Expand Down Expand Up @@ -42,8 +42,7 @@ impl_nonzero_type_layout! {
}

unsafe impl<T: TypeLayout> TypeLayout for core::num::Wrapping<T> {
type Inhabited = T::Inhabited;

const INHABITED: crate::MaybeUninhabited = T::INHABITED;
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand All @@ -64,8 +63,7 @@ unsafe impl<T: ComputeTypeSet> ComputeTypeSet for core::num::Wrapping<T> {
}

unsafe impl<T: TypeLayout> TypeLayout for core::num::Saturating<T> {
type Inhabited = T::Inhabited;

const INHABITED: crate::MaybeUninhabited = T::INHABITED;
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand Down
21 changes: 7 additions & 14 deletions src/impls/core/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use crate::{
};

unsafe impl<Idx: TypeLayout> TypeLayout for core::ops::Range<Idx> {
type Inhabited = Idx::Inhabited;

const INHABITED: crate::MaybeUninhabited = Idx::INHABITED;
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand Down Expand Up @@ -33,8 +32,7 @@ unsafe impl<Idx: ComputeTypeSet> ComputeTypeSet for core::ops::Range<Idx> {
}

unsafe impl<Idx: TypeLayout> TypeLayout for core::ops::RangeFrom<Idx> {
type Inhabited = Idx::Inhabited;

const INHABITED: crate::MaybeUninhabited = Idx::INHABITED;
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand All @@ -55,8 +53,7 @@ unsafe impl<Idx: ComputeTypeSet> ComputeTypeSet for core::ops::RangeFrom<Idx> {
}

unsafe impl TypeLayout for core::ops::RangeFull {
type Inhabited = crate::inhabited::Inhabited;

const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![];
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand All @@ -73,8 +70,7 @@ unsafe impl ComputeTypeSet for core::ops::RangeFull {
}

unsafe impl<Idx: TypeLayout> TypeLayout for core::ops::RangeTo<Idx> {
type Inhabited = Idx::Inhabited;

const INHABITED: crate::MaybeUninhabited = Idx::INHABITED;
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand All @@ -95,8 +91,7 @@ unsafe impl<Idx: ComputeTypeSet> ComputeTypeSet for core::ops::RangeTo<Idx> {
}

unsafe impl<Idx: TypeLayout> TypeLayout for core::ops::RangeToInclusive<Idx> {
type Inhabited = Idx::Inhabited;

const INHABITED: crate::MaybeUninhabited = Idx::INHABITED;
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand All @@ -117,8 +112,7 @@ unsafe impl<Idx: ComputeTypeSet> ComputeTypeSet for core::ops::RangeToInclusive<
}

unsafe impl<T: TypeLayout> TypeLayout for core::ops::Bound<T> {
type Inhabited = crate::inhabited::Inhabited;

const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![];
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand Down Expand Up @@ -165,8 +159,7 @@ unsafe impl<T: ComputeTypeSet> ComputeTypeSet for core::ops::Bound<T> {
}

unsafe impl<B: TypeLayout, C: TypeLayout> TypeLayout for core::ops::ControlFlow<B, C> {
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::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand Down
3 changes: 1 addition & 2 deletions src/impls/core/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use crate::{
};

unsafe impl<T: TypeLayout> TypeLayout for core::option::Option<T> {
type Inhabited = crate::inhabited::Inhabited;

const INHABITED: crate::MaybeUninhabited = crate::inhabited::all![];
const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
name: ::core::any::type_name::<Self>(),
size: ::core::mem::size_of::<Self>(),
Expand Down
Loading