Skip to content

Compile error with #[derive(Type)] starting from nightly-2024-04-05 #3185

Closed
@benwh1

Description

@benwh1

Bug Description

The code below does not compile on nightly-2024-04-05 or later.

Minimal Reproduction

use sqlx::Type;

#[derive(Type)]
struct Foo {
    a: i32,
}

fn main() {}
error: lifetime may not live long enough
  --> src/main.rs:3:10
   |
3  | #[derive(Type)]
   |          ^^^^
   |          |
   |          lifetime `'r` defined here
   |          requires that `'r` must outlive `'static`
   |          in this derive macro expansion
   |
  ::: /home/ben/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-macros-0.7.4/src/lib.rs:43:1
   |
43 | pub fn derive_type(tokenstream: TokenStream) -> TokenStream {
   | ----------------------------------------------------------- in this expansion of `#[derive(Type)]`
   |
note: due to current limitations in the borrow checker, this implies a `'static` lifetime
  --> /home/ben/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-postgres-0.7.4/src/types/record.rs:97:12
   |
97 |         T: for<'a> Decode<'a, Postgres> + Type<Postgres>,
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: implementation of `sqlx::Decode` is not general enough
  --> src/main.rs:3:10
   |
3  | #[derive(Type)]
   |          ^^^^
   |          |
   |          implementation of `sqlx::Decode` is not general enough
   |          in this derive macro expansion
   |
  ::: /home/ben/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-macros-0.7.4/src/lib.rs:43:1
   |
43 | pub fn derive_type(tokenstream: TokenStream) -> TokenStream {
   | ----------------------------------------------------------- in this expansion of `#[derive(Type)]`
   |
   = note: `i32` must implement `sqlx::Decode<'0, Postgres>`, for any lifetime `'0`...
   = note: ...but it actually implements `sqlx::Decode<'1, Postgres>`, for some specific lifetime `'1`

error: could not compile `testing` (bin "testing") due to 2 previous errors

Info

  • SQLx version: sqlx = { version = "0.7.4", features = ["postgres"] }
  • Database server and version: psql (PostgreSQL) 16.2 (Ubuntu 16.2-1.pgdg20.04+1)
  • Operating system: Linux Mint 20.1 x86_64
  • rustc --version: nightly-2024-04-05

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