Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
IsseW committed Nov 21, 2023
1 parent 97dfc62 commit eabfbb1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions bauble_macro_util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ struct TypeInfo<'a> {
ty: TokenStream,
/// The type's generics
impl_generics: &'a ImplGenerics<'a>,
has_generics: bool,
where_clause: &'a WhereClause,
}

Expand All @@ -219,6 +220,7 @@ fn derive_fields(
TypeInfo {
ty,
impl_generics,
has_generics,
where_clause,
}: TypeInfo,
// The struct or variant's fields
Expand Down Expand Up @@ -395,9 +397,15 @@ fn derive_fields(
// Generate code that evaluates each field
// TODO The way `impl_generics` is used here prevents the user from adding bounds directly on
// the type parameters

let fields = fields.iter().map(|field| {
let ident = &field.name;
let default = format_ident!("default_{ident}");
let default_call = if has_generics {
quote! { #default::#impl_generics() }
} else {
quote! { #default() }
};
match (&field.ty, flatten) {
(
FieldTy::Val {
Expand Down Expand Up @@ -438,7 +446,7 @@ fn derive_fields(
allocator,
::bauble::FromBauble::from_bauble(value, allocator)?,
)?,
None => #default(),
None => #default_call,
}
},
(
Expand All @@ -463,7 +471,7 @@ fn derive_fields(
::bauble::FromBauble::from_bauble(values.#index, allocator)?
)?
},
(FieldTy::AsDefault { .. }, _) => quote! { #ident: #default() },
(FieldTy::AsDefault { .. }, _) => quote! { #ident: #default_call },
}
});

Expand Down Expand Up @@ -730,6 +738,7 @@ pub fn derive_bauble_derive_input(
TypeInfo {
ty: quote! { Self },
impl_generics: &impl_generics,
has_generics: generics.params.len() > 1,
where_clause: &where_clause,
},
&fields,
Expand Down Expand Up @@ -854,6 +863,7 @@ pub fn derive_bauble_derive_input(
TypeInfo {
ty: quote! { Self::#ident },
impl_generics: &impl_generics,
has_generics: generics.params.len() > 1,
where_clause: &where_clause,
},
&fields,
Expand Down

0 comments on commit eabfbb1

Please sign in to comment.