mirror of
https://github.com/Lokathor/bytemuck.git
synced 2024-11-28 17:52:22 +00:00
Blame struct name, better error for padding (#35)
This commit is contained in:
parent
e053f8b456
commit
19e61623d7
@ -210,17 +210,16 @@ fn generate_assert_no_padding(
|
|||||||
input: &DeriveInput,
|
input: &DeriveInput,
|
||||||
) -> Result<TokenStream, &'static str> {
|
) -> Result<TokenStream, &'static str> {
|
||||||
let struct_type = &input.ident;
|
let struct_type = &input.ident;
|
||||||
let span = input.span();
|
let span = input.ident.span();
|
||||||
let fields = get_struct_fields(input)?;
|
let fields = get_struct_fields(input)?;
|
||||||
|
|
||||||
let field_types = get_field_types(&fields);
|
let field_types = get_field_types(&fields);
|
||||||
let struct_size =
|
|
||||||
quote_spanned!(span => ::core::mem::size_of::<#struct_type>());
|
|
||||||
let size_sum =
|
let size_sum =
|
||||||
quote_spanned!(span => 0 #( + ::core::mem::size_of::<#field_types>() )*);
|
quote_spanned!(span => 0 #( + ::core::mem::size_of::<#field_types>() )*);
|
||||||
|
|
||||||
Ok(quote_spanned! {span => const _: fn() = || {
|
Ok(quote_spanned! {span => const _: fn() = || {
|
||||||
let _ = ::core::mem::transmute::<[u8; #struct_size], [u8; #size_sum]>;
|
struct TypeWithoutPadding([u8; #size_sum]);
|
||||||
|
let _ = ::core::mem::transmute::<#struct_type, TypeWithoutPadding>;
|
||||||
};})
|
};})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user