Skip to content

Trait bounds not met #12

@jmoore34

Description

@jmoore34

Unrelated to #10, while I can now get the derive on a struct with a lifetime parameter to compile, I can't get the usage of it in a function to compile.

Minimal example:

// The derive compiles fine now
#[derive(FromRow)]
struct User<'b> {
    id: i32,
    username: &'b str
}

// However, there's a lifetime issue when trying to use the derived function:
fn get_user_by_id<'c>(db: &mut impl postgres::GenericClient, id: i32) -> Result<User<'c>, postgres::Error> {
    let row = db.query_one("SELECT * FROM User WHERE id = $1", &[&id])?;
    User::try_from_row(&row)
}

Error:

error[E0599]: the function or associated item `try_from_row` exists for struct `User<'_>`, but its trait bounds were not satisfied
  --> tests/integration.rs:14:11
   |
6  | struct User<'b> {
   | ---------------
   | |
   | function or associated item `try_from_row` not found for this struct
   | doesn't satisfy `User<'_>: FromRow`
...
14 |     User::try_from_row(&row)
   |           ^^^^^^^^^^^^ function or associated item cannot be called on `User<'_>` due to unsatisfied trait bounds
   |
   = note: trait bound `&str: FromSql<'__from_row_lifetime>` was not satisfied

(Note that this error at the usage site appears both with and without #11, just with the lifetime name in the error changed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions