Updating from_sql_row
@@ -9,8 +9,13 @@ pub fn derive(mut item: syn::DeriveInput) -> Result<TokenStream, Diagnostic> {
MetaItem::with_name(&item.attrs, "diesel").unwrap_or_else(|| MetaItem::empty("diesel"));
let struct_ty = ty_for_foreign_derive(&item, &flags)?;
- item.generics.params.push(parse_quote!(__ST));
- item.generics.params.push(parse_quote!(__DB));
+ // To prevent double issue with mutable borrow below while creating where clause
+ let initial_item = item.clone();
+
+ let lifetimes = initial_item.generics.lifetimes().collect::<Vec<_>>();
+ let ty_params = initial_item.generics.type_params().collect::<Vec<_>>();
+ let const_params = initial_item.generics.const_params().collect::<Vec<_>>();
+
{
let where_clause = item
.generics
@@ -26,12 +31,13 @@ pub fn derive(mut item: syn::DeriveInput) -> Result<TokenStream, Diagnostic> {
.predicates
.push(parse_quote!(Self: FromSql<__ST, __DB>));
}
- let (impl_generics, _, where_clause) = item.generics.split_for_impl();
+ let (_, _, where_clause) = item.generics.split_for_impl();
Ok(wrap_in_dummy_mod(quote! {
use diesel::deserialize::{self, FromSql, Queryable};
- impl #impl_generics Queryable<__ST, __DB> for #struct_ty
+ // Need to put __ST and __DB after lifetimes but before const params
+ impl<#(#lifetimes,)* __ST, __DB, #(#ty_params,)* #(#const_params,)*> Queryable<__ST, __DB> for #struct_ty
#where_clause
{
type Row = Self;
