Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various small fixes to the derive macros #168

Merged
merged 4 commits into from
Jan 26, 2023
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: 1 addition & 1 deletion derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!()
};
Expand Down
9 changes: 7 additions & 2 deletions derive/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
))
Expand Down Expand Up @@ -609,6 +609,8 @@ mk_repr! {
I64 => i64,
I128 => i128,
U128 => u128,
Usize => usize,
Isize => isize,
}
// where
macro_rules! mk_repr {(
Expand Down Expand Up @@ -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 {
Expand Down