Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
benwh1 opened this issue Apr 8, 2024 · 5 comments
Closed

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

benwh1 opened this issue Apr 8, 2024 · 5 comments
Labels

Comments

@benwh1
Copy link

benwh1 commented Apr 8, 2024

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 benwh1 added the bug label Apr 8, 2024
@syphar
Copy link

syphar commented Apr 9, 2024

For some context:

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

@HHogg
Copy link

HHogg commented Apr 22, 2024

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.

@demurgos
Copy link
Contributor

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.

@abonander
Copy link
Collaborator

closed by #2940

@42triangles
Copy link

42triangles commented Jun 14, 2024

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: rust-lang/rust#125629

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants