-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
Description
I have found these related issues/pull requests
#3195 seems to mention this issue, but in a different context.
Description
This codegen snippet omits generic types when generating the sqlx::Type
impl:
sqlx/sqlx-macros-core/src/derives/type.rs
Lines 244 to 263 in 9079720
tts.extend(quote!( | |
#[automatically_derived] | |
impl ::sqlx::Type<::sqlx::Postgres> for #ident { | |
fn type_info() -> ::sqlx::postgres::PgTypeInfo { | |
::sqlx::postgres::PgTypeInfo::with_name(#ty_name) | |
} | |
} | |
)); | |
if !attributes.no_pg_array { | |
tts.extend(quote!( | |
#[automatically_derived] | |
impl ::sqlx::postgres::PgHasArrayType for #ident { | |
fn array_type_info() -> ::sqlx::postgres::PgTypeInfo { | |
::sqlx::postgres::PgTypeInfo::array_of(#ty_name) | |
} | |
} | |
)); | |
} | |
} |
The same file contains a valid codegen logic just above the previously mentioned code fragment:
sqlx/sqlx-macros-core/src/derives/type.rs
Lines 87 to 110 in 9079720
let mut tokens = quote!( | |
#[automatically_derived] | |
impl #impl_generics ::sqlx::Type< DB > for #ident #ty_generics #where_clause { | |
fn type_info() -> DB::TypeInfo { | |
<#ty as ::sqlx::Type<DB>>::type_info() | |
} | |
fn compatible(ty: &DB::TypeInfo) -> ::std::primitive::bool { | |
<#ty as ::sqlx::Type<DB>>::compatible(ty) | |
} | |
} | |
); | |
if cfg!(feature = "postgres") && !attr.no_pg_array { | |
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() | |
} | |
} | |
)); | |
} |
Reproduction steps
- Create a struct with a generic type
- Derive
sqlx::Type
for it - Enable
postgres
-related features in sqlx
This should result in an error similar to this one:
error[E0107]: missing generics for struct `Test`
--> [snip]
|
118 | pub struct Test<OC: Serialize + DeserializeOwned + 'static> {
| ^^^^ expected 1 generic argument
|
note: struct defined here, with 1 generic parameter: `OC`
--> [snip]
|
118 | pub struct Test<OC: Serialize + DeserializeOwned + 'static> {
| ^^^^ --
help: add missing generic argument
|
118 | pub struct Test<OC><OC: Serialize + DeserializeOwned + 'static> {
| ++++
SQLx version
0.8.6
Enabled SQLx features
runtime-tokio-native-tls,postgres,chrono,json,macros,migrate,uuid
Database server and version
Postgres 16.9
Operating system
NixOS 25.05
Rust version
rustc 1.87.0 (17067e9ac 2025-05-09)