Skip to content

Code that compiles under deadpool-postgres 0.12.1 fails to compile under 0.13.2 #323

@and-reas-se

Description

@and-reas-se

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.

use deadpool_postgres::{tokio_postgres::Row, GenericClient};
use futures_util::{Stream, StreamExt};
use postgres_types::ToSql;
use std::future::Future;

// 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 {
        async {
            let rows = db.query_raw("SELECT 1", slice_iter(params)).await.unwrap();
            rows.map(|row| row.unwrap())
        }
    }
}

This code compiles with 0.12.1, but with 0.13.2 you get this error:

error[E0308]: mismatched types
  --> repro/src/lib.rs:18:9
   |
18 | /         async {
19 | |             let rows = db.query_raw("SELECT 1", slice_iter(params)).await.unwrap();
20 | |             rows.map(|row| row.unwrap())
21 | |         }
   | |_________^ one type is more general than the other
   |
   = note: expected reference `&dyn ToSql`
              found reference `&dyn ToSql`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `repro` (lib) due to 1 previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-postgresArea: PostgreSQL support / deadpool-postgresbugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions