-
Notifications
You must be signed in to change notification settings - Fork 139
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
Code that compiles under deadpool-postgres 0.12.1 fails to compile under 0.13.2 #323
Comments
Could you please post the output of
It looks like you're using two versions of the
use deadpool_postgres::tokio_postgres::types::ToSql; That way you're guaranteed that you don't mix versions by accident. It just gets a bit more tricky if you need specific features of |
It doesn't look like that's the problem, same error message after adjusting the import. But thanks for the tip. |
Could you share the code of the |
Cargo.toml [package]
name = "repro"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
deadpool-postgres = "0.13.2"
futures-util = "0.3.30" Then lib.rs as per the first post. That's the entire thing. |
After pasting the code into my own code base I was able to reproduce this issue. This almost looks like a compiler bug. Usually the error messages are more meaningful than that. |
This seems to support your suspicion: rust-lang/rust#112985 Think there's any chance of a workaround, or should I downgrade for now? |
The error is completely misleading. After removing the pub trait PgQuery {
async fn query_raw(
db: &impl GenericClient,
params: &[&(dyn ToSql + Sync)],
- ) -> impl Future<Output = impl Stream<Item = Row>> + Send {
+ ) -> impl Future<Output = impl Stream<Item = Row>> {
let fut = async {
let rows = db.query_raw("SELECT 1", slice_iter(params)).await.unwrap();
rows.map(|row| row.unwrap())
};
fut
}
} Now that I think about it it just makes sense. The compiler just forgot to tell you that it's caused by the params not being |
After copying the method signature from pub trait PgQuery {
fn query_raw<P, I>(
db: &impl GenericClient,
params: I,
) -> impl Future<Output = impl Stream<Item = Row>> + Send
where
P: BorrowToSql,
I: IntoIterator<Item = P> + Sync + Send,
I::IntoIter: ExactSizeIterator,
{
async {
let rows = db.query_raw("SELECT 1", params).await.unwrap();
rows.map(|row| row.unwrap())
}
}
} The signature from The issue you were facing lies somewhere inside a missing I do wonder why your code worked with the previous Edit: Removed unused generic |
I consider this a bug as it breaks existing code and is not a drop-in replacement for the old As far as I can tell it's actually a lifetime issue and has nothing to do with the This is only an issue for The easiest fix at the moment would be to reintroduce |
I agree that it's likely a lifetime issue, when messing around with my codebase I got it to produce errors like these instead, again only with the new version:
I was planning on posting an example demonstrating this, but it was more complicated to reduce to a small example, so I hadn't completed it. Seems to not be necessary now. Edit: That's just an example, the same error appear for multiple traits and types, it's not specific to Send and Transaction. |
Thank you @conradludgate for pointing me to this page: I'll give this a try and see if this fixes it. Otherwise I'll revert back to |
Interesting, removing async, it works: // this function borrowed from tokio_postgres source code
fn slice_iter<'a>(
s: &'a [&'a (dyn ToSql + Sync)],
) -> impl ExactSizeIterator<Item = &'a dyn ToSql> + 'a {
s.iter().map(|s| *s as _)
}
pub trait PgQuery {
fn query_raw(
db: &impl GenericClient,
params: &[&(dyn ToSql + Sync)],
) -> impl Future<Output = impl Stream<Item = Row>> + Send {
let query = db.query_raw("SELECT 1", slice_iter(params));
query.map(|rows| rows.unwrap().map(|row| row.unwrap()))
}
} |
Adding As I have not been able to fix this problem I'm leaning towards re-introducing |
I investigated a bit. It did not really come to anything, but I created an example that reproduces the problem, that does not use any dependencies, and has somewhat simplified signatures. I figured I'd share it if anyone else wanted an easier starting point for experimentation. // this function borrowed from tokio_postgres source code
fn slice_iter<'a>(
s: &'a [&'a (dyn ToSql + Sync)],
) -> impl ExactSizeIterator<Item = &'a dyn ToSql> + 'a {
s.iter().map(|s| *s as _)
}
pub trait PgQuery {
fn query_raw(
db: &impl GenericClient,
params: &[&(dyn ToSql + Sync)],
) -> impl std::future::Future<Output = ()> + Send {
async {
db.query_raw(slice_iter(params)).await;
}
}
}
pub trait ToSql {}
pub trait BorrowToSql {}
impl BorrowToSql for &dyn ToSql {}
pub trait GenericClient: Sync {
// with signature for query_raw it fails to compile
fn query_raw<P, I>(&self, params: I) -> impl std::future::Future<Output = ()> + Send
where
P: BorrowToSql,
I: IntoIterator<Item = P> + Sync + Send;
// with this signature for query_raw it compiles
// fn query_raw<'async_trait, P, I>(
// &self,
// params: I,
// ) -> std::pin::Pin<Box<dyn std::future::Future<Output = ()> + Send + 'async_trait>>
// where
// P: BorrowToSql,
// I: IntoIterator<Item = P> + Sync + Send;
} |
I reverted back to using |
I just released I've opened a new tracking issue for the removal of |
Sorry for the non-specific title, but I don't really understand this issue. I don't have any guesses as to what's wrong. But here's the most minimal repro I could make.
This code compiles with 0.12.1, but with 0.13.2 you get this error:
The text was updated successfully, but these errors were encountered: