mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-27 07:04:35 +00:00
Merge pull request #131 from cormacrelf/bad-derive-default
Manually implement Default for *GroupStorage
This commit is contained in:
commit
1b04ac19ff
1 changed files with 13 additions and 1 deletions
|
@ -135,6 +135,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream
|
|||
let mut query_descriptor_variants = proc_macro2::TokenStream::new();
|
||||
let mut query_descriptor_maybe_change = proc_macro2::TokenStream::new();
|
||||
let mut storage_fields = proc_macro2::TokenStream::new();
|
||||
let mut storage_defaults = proc_macro2::TokenStream::new();
|
||||
for query in &queries {
|
||||
let key_names: &Vec<_> = &(0..query.keys.len())
|
||||
.map(|i| Ident::new(&format!("key{}", i), Span::call_site()))
|
||||
|
@ -221,6 +222,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream
|
|||
storage_fields.extend(quote! {
|
||||
pub #fn_name: <#qt as salsa::Query<DB__>>::Storage,
|
||||
});
|
||||
storage_defaults.extend(quote! { #fn_name: Default::default(), });
|
||||
}
|
||||
|
||||
// Emit the trait itself.
|
||||
|
@ -366,12 +368,22 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream
|
|||
}
|
||||
|
||||
// Emit query group storage struct
|
||||
// It would derive Default, but then all database structs would have to implement Default
|
||||
// as the derived version includes an unused `+ Default` constraint.
|
||||
output.extend(quote! {
|
||||
#[derive(Default)]
|
||||
#trait_vis struct #group_storage<DB__: #trait_name> {
|
||||
#storage_fields
|
||||
}
|
||||
|
||||
impl<DB__: #trait_name> Default for #group_storage<DB__> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
#group_storage {
|
||||
#storage_defaults
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB__> #group_storage<DB__>
|
||||
where
|
||||
DB__: #trait_name,
|
||||
|
|
Loading…
Reference in a new issue