sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

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

Open benwh1 opened this issue 1 year ago • 2 comments

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

benwh1 avatar Apr 08 '24 13:04 benwh1

For some context:

this is coming from https://github.com/rust-lang/rust/pull/119820, which is an intentional breaking change, coming to Rust 1.79. ( we at docs.rs are also impacted: https://github.com/rust-lang/docs.rs/issues/2488 )

syphar avatar Apr 09 '24 05:04 syphar

I'm also seeing this. On the plus side, I learned how to downgrade a rust version from this. If you're here and need to do the same, here's how...

# Install the version before the broken one. 
rustup install nightly-2024-04-04 

# Set the version to the installed one 
rustup override set nightly-2024-04-04

I can confirm nightly-2024-04-04 works fine.

HHogg avatar Apr 22 '24 19:04 HHogg

Bumping this issue: the problem happens in Rust 1.79 which is currently in beta. It is set to release this change in just 3 weeks! @lcnr posted a comment that they would try to delay the change, but so far it's still in the beta.

Please merge the PR with the fix without waiting too much, it already feels like it's cutting it fairly close.

demurgos avatar May 25 '24 20:05 demurgos

closed by #2940

abonander avatar May 31 '24 20:05 abonander

Just in case anyone who's following this issue is wondering, the new stable release didn't break things depending on sqlx, they temporarily reverted the change: https://github.com/rust-lang/rust/pull/125629

42triangles avatar Jun 14 '24 16:06 42triangles