mirror of
https://github.com/Lokathor/bytemuck.git
synced 2024-11-21 22:32:23 +00:00
various small fixes to the derive macros (#168)
* parse `repr(usize)` and `repr(isize)` This can be used with enums. * emit packed repr without type suffix Previously we emitted the packed attribute with a type suffix for the value `packed(4u32)`. This is not allowed. Instead we should emit `packed(4)`. * read bits instead of creating reference This is required for packed structs where creating a reference to fields is not allowed. We can make a copy of the bits because the bits are `AnyBitPattern` which implies `Copy`. * emit generics on implied traits
This commit is contained in:
parent
49c23727fa
commit
2d1f876216
@ -334,7 +334,7 @@ fn derive_marker_trait_inner<Trait: Derivable>(
|
||||
let (trait_impl_extras, trait_impl) = Trait::trait_impl(&input)?;
|
||||
|
||||
let implies_trait = if let Some(implies_trait) = Trait::implies_trait() {
|
||||
quote!(unsafe impl #implies_trait for #name {})
|
||||
quote!(unsafe impl #impl_generics #implies_trait for #name #ty_generics #where_clause {})
|
||||
} else {
|
||||
quote!()
|
||||
};
|
||||
|
@ -432,7 +432,7 @@ fn generate_checked_bit_pattern_struct(
|
||||
#[inline]
|
||||
#[allow(clippy::double_comparisons)]
|
||||
fn is_valid_bit_pattern(bits: &#bits_ty) -> bool {
|
||||
#(<#field_ty as ::bytemuck::CheckedBitPattern>::is_valid_bit_pattern(&bits.#field_name) && )* true
|
||||
#(<#field_ty as ::bytemuck::CheckedBitPattern>::is_valid_bit_pattern(&{ bits.#field_name }) && )* true
|
||||
}
|
||||
},
|
||||
))
|
||||
@ -609,6 +609,8 @@ mk_repr! {
|
||||
I64 => i64,
|
||||
I128 => i128,
|
||||
U128 => u128,
|
||||
Usize => usize,
|
||||
Isize => isize,
|
||||
}
|
||||
// where
|
||||
macro_rules! mk_repr {(
|
||||
@ -705,7 +707,10 @@ macro_rules! mk_repr {(
|
||||
Repr::$Xn => Some(quote!($xn)),
|
||||
)*
|
||||
};
|
||||
let packed = self.packed.map(|p| quote!(packed(#p)));
|
||||
let packed = self.packed.map(|p| {
|
||||
let lit = LitInt::new(&p.to_string(), Span::call_site());
|
||||
quote!(packed(#lit))
|
||||
});
|
||||
let comma = if packed.is_some() && repr.is_some() {
|
||||
Some(quote!(,))
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user