Skip to content

Generic types are not handled properly in the Type proc-macro #3882

Description

@ivan770

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:
https://github.com/launchbadge/sqlx/blob/90797200eef8d7aa41ce0cd582fdd8560bfc0f24/sqlx-macros-core/src/derives/type.rs#L244-L263

The same file contains a valid codegen logic just above the previously mentioned code fragment:
https://github.com/launchbadge/sqlx/blob/90797200eef8d7aa41ce0cd582fdd8560bfc0f24/sqlx-macros-core/src/derives/type.rs#L87-L110

Reproduction steps

  1. Create a struct with a generic type
  2. Derive sqlx::Type for it
  3. 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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions