Reputation: 1102
I have code that used to work on nightly-2016-11-15. When I upgraded to 1.15.1 stable, I started getting a bunch of errors about type implementations not being found. Here's an example:
error[E0277]: the trait bound `errors::Error: core::convert::From<r2d2_postgres::<unnamed>::error::Error>` is not satisfied
--> src/pg/datastore.rs:79:23
|
79 | let results = conn.query("DELETE FROM accounts WHERE id=$1 RETURNING 1", &[&account_id])?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::convert::From<r2d2_postgres::<unnamed>::error::Error>` is not implemented for `errors::Error`
|
= help: the following implementations were found:
= help: <errors::Error as core::convert::From<r2d2_postgres::Error>>
= help: <errors::Error as core::convert::From<postgres::error::Error>>
= help: <errors::Error as core::convert::From<r2d2::GetTimeout>>
= help: <errors::Error as core::convert::From<rocksdb::Error>>
= help: and 3 others
= note: required by `core::convert::From::from`
... even though there is a relevant From
implementation. Here's a shortened version:
use std::error::Error as StdError;
use r2d2::GetTimeout;
use postgres::error::Error as PostgresError;
use r2d2_postgres::Error as R2D2PostgresError;
use super::fmt;
#[derive(Eq, PartialEq, Clone, Debug)]
pub enum Error {
Unexpected(String),
...
}
impl StdError for Error {
fn description(&self) -> &str {
...
}
fn cause(&self) -> Option<&StdError> {
None
}
}
impl From<R2D2PostgresError> for Error {
fn from(err: R2D2PostgresError) -> Error {
Error::Unexpected(format!("{}", err))
}
}
impl From<PostgresError> for Error {
fn from(err: PostgresError) -> Error {
Error::Unexpected(pg_error_to_description(err))
}
}
impl From<GetTimeout> for Error {
fn from(err: GetTimeout) -> Error {
Error::Unexpected(format!("Could not fetch connection: {}", err))
}
}
I think this has something to do with the use of associated types, as it doesn't appear to happen in other contexts. Additionally, the namespace r2d2_postgres::<unnamed>::error::Error
doesn't make sense - what is <unnamed>
? Here is the relevant type association.
Upvotes: 1
Views: 293
Reputation: 1102
This turned out to be due to version conflicts. I had switched to postgres
's master branch to fix a separate version conflict, but r2d2_postgres
was referencing a different version of postgres
.
Luckily, as explained in this issue, Cargo.toml
has a [replace]
section that allows you to handle it like this:
[replace]
"postgres:0.13.6" = { git = "https://github.com/sfackler/rust-postgres" }
Upvotes: 2