@@ -9,8 +9,13 @@ pub fn derive(mut item: syn::DeriveInput) -> Result<TokenStream, Diagnostic> {
99 MetaItem :: with_name ( & item. attrs , "diesel" ) . unwrap_or_else ( || MetaItem :: empty ( "diesel" ) ) ;
1010 let struct_ty = ty_for_foreign_derive ( & item, & flags) ?;
1111
12- item. generics . params . push ( parse_quote ! ( __ST) ) ;
13- item. generics . params . push ( parse_quote ! ( __DB) ) ;
12+ // To prevent double issue with mutable borrow below while creating where clause
13+ let initial_item = item. clone ( ) ;
14+
15+ let lifetimes = initial_item. generics . lifetimes ( ) . collect :: < Vec < _ > > ( ) ;
16+ let ty_params = initial_item. generics . type_params ( ) . collect :: < Vec < _ > > ( ) ;
17+ let const_params = initial_item. generics . const_params ( ) . collect :: < Vec < _ > > ( ) ;
18+
1419 {
1520 let where_clause = item
1621 . generics
@@ -26,12 +31,13 @@ pub fn derive(mut item: syn::DeriveInput) -> Result<TokenStream, Diagnostic> {
2631 . predicates
2732 . push ( parse_quote ! ( Self : FromSql <__ST, __DB>) ) ;
2833 }
29- let ( impl_generics , _, where_clause) = item. generics . split_for_impl ( ) ;
34+ let ( _ , _, where_clause) = item. generics . split_for_impl ( ) ;
3035
3136 Ok ( wrap_in_dummy_mod ( quote ! {
3237 use diesel:: deserialize:: { self , FromSql , Queryable } ;
3338
34- impl #impl_generics Queryable <__ST, __DB> for #struct_ty
39+ // Need to put __ST and __DB after lifetimes but before const params
40+ impl <#( #lifetimes, ) * __ST, __DB, #( #ty_params, ) * #( #const_params, ) * > Queryable <__ST, __DB> for #struct_ty
3541 #where_clause
3642 {
3743 type Row = Self ;
0 commit comments