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

Fix "requires that 'r must outlive 'static" #3223

Closed
wants to merge 1 commit into from

Conversation

bewee-i
Copy link

@bewee-i bewee-i commented May 3, 2024

When building the following on nightly

#[derive(sqlx::Type)]
struct Foobar {
    a: String,
}

Compilation fails with

error: lifetime may not live long enough
  --> tests/foo.rs:1:10
   |
5  | #[derive(sqlx::Type)]
   |          ^^^^^^^^^^
   |          |
   |          lifetime `'r` defined here
   |          requires that `'r` must outlive `'static`
   |
note: due to current limitations in the borrow checker, this implies a `'static` lifetime
  --> /home/b/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.6.3/src/postgres/types/record.rs:97:12
   |
97 |         T: for<'a> Decode<'a, Postgres> + Type<Postgres>,
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the derive macro `sqlx::Type` (in Nightly builds, run with -Z macro-backtrace for more info)

error: implementation of `sqlx::Decode` is not general enough
 --> tests/foo.rs:5:10
  |
5 | #[derive(sqlx::Type)]
  |          ^^^^^^^^^^ implementation of `sqlx::Decode` is not general enough
  |
  = note: `std::string::String` must implement `sqlx::Decode<'0, Postgres>`, for any lifetime `'0`...
  = note: ...but it actually implements `sqlx::Decode<'1, Postgres>`, for some specific lifetime `'1`
  = note: this error originates in the derive macro `sqlx::Type` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `foo` (test "foo") due to 2 previous errors

To quick-fix this in our project, we resorted to expanding the code generated by sqlx::Type and manually applying the fix that this PR now proposes to implement in the macro.

The changes are not tested yet, but I could invest some additional effort if you can guide me.

@joelawm
Copy link

joelawm commented May 5, 2024

Awesome work! Does this fix?

#[derive(sqlx::Type)]
pub struct Foo {
    pub barz: i32,
    pub bars: String,
    pub bara: Option<String>
}

Many other people have tried providing fixes and composite types in Postgres can return null and this is directly related.

@bewee-i
Copy link
Author

bewee-i commented May 6, 2024

@joelawm Yep, that one seems to be fixed as well

@joelawm
Copy link

joelawm commented May 7, 2024

@bewee-i Amazing work! @abonander will probably tell you to create some Tests proving that it can handle yours and my example. This could also close out some other existing PR's that seem to be more complicated. I myself will also be testing this locally since I need a similar fix for this, so I will post when I have some basic E2E local tests working.

@bewee-i
Copy link
Author

bewee-i commented May 27, 2024

Hey @joelawm @abonander, any concrete updates on what is required from my end to make this ready?

@abonander
Copy link
Collaborator

Superceded by #2940

@abonander abonander closed this May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants