From f9ba660fb3a99088b04ae44688dda0f01676e282 Mon Sep 17 00:00:00 2001 From: Daniel Tashjian Date: Tue, 6 Sep 2022 17:09:49 -0400 Subject: [PATCH] PgHasArrayType for transparent types fix. (#2086) Problem: PgHasArrayType was checking the application's postgres feature Solution: only check the library's postgres feature Co-authored-by: Daniel Tashjian --- sqlx-macros/src/derives/type.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/sqlx-macros/src/derives/type.rs b/sqlx-macros/src/derives/type.rs index 065a5be490..2dd1d3fdfc 100644 --- a/sqlx-macros/src/derives/type.rs +++ b/sqlx-macros/src/derives/type.rs @@ -77,7 +77,7 @@ fn expand_derive_has_sql_type_transparent( .push(parse_quote!(#ty: ::sqlx::postgres::PgHasArrayType)); let (array_impl_generics, _, array_where_clause) = array_generics.split_for_impl(); - return Ok(quote!( + let mut tokens = quote!( #[automatically_derived] impl #impl_generics ::sqlx::Type< DB > for #ident #ty_generics #where_clause { fn type_info() -> DB::TypeInfo { @@ -88,15 +88,21 @@ fn expand_derive_has_sql_type_transparent( <#ty as ::sqlx::Type>::compatible(ty) } } - #[automatically_derived] - #[cfg(feature = "postgres")] - impl #array_impl_generics ::sqlx::postgres::PgHasArrayType for #ident #ty_generics - #array_where_clause { - fn array_type_info() -> ::sqlx::postgres::PgTypeInfo { - <#ty as ::sqlx::postgres::PgHasArrayType>::array_type_info() + ); + + if cfg!(feature = "postgres") { + tokens.extend(quote!( + #[automatically_derived] + impl #array_impl_generics ::sqlx::postgres::PgHasArrayType for #ident #ty_generics + #array_where_clause { + fn array_type_info() -> ::sqlx::postgres::PgTypeInfo { + <#ty as ::sqlx::postgres::PgHasArrayType>::array_type_info() + } } - } - )); + )); + } + + return Ok(tokens); } let mut tts = TokenStream::new();