Skip to content

TryFrom for now-incompatible type falls back to From error message #71693

Open
@jonathanGB

Description

@jonathanGB

I am working on a library which at some point converts a mysql_common::value::Value to a type DataType via DataType::try_from(<value>). I am using an impl TryFrom<mysql_common::value::Value> for DataType defined in a separate crate, which worked well initially. However, this other crate has since then bumped up the dependencies, such that my project was now using a version of Value incompatible to the one used by the other crate.

The compiler complained (see error message) that "the trait std::convert::From<mysql_common::value::Value> is not implemented for DataType", and that the conversion was infallible. I think it would have been clearer and easier to debug had the compiler error message rather said that TryFrom was implemented for a type by the same name but incompatible (different version), rather than fall back on a blanket implementation error message which was deceptive in this case.

Error message

error[E0277]: the trait bound `noria::data::DataType: std::convert::From<mysql_common::value::Value>` is not satisfied
   --> src/lib.rs:283:19
    |
283 |             match DataType::try_from(value) {
    |                   ^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<mysql_common::value::Value>` is not implemented for `noria::data::DataType`
    |
    = help: the following implementations were found:
              <noria::data::DataType as std::convert::From<&'a nom_sql::common::Literal>>
              <noria::data::DataType as std::convert::From<&'a noria::data::DataType>>
              <noria::data::DataType as std::convert::From<&'a str>>
              <noria::data::DataType as std::convert::From<chrono::naive::datetime::NaiveDateTime>>
            and 11 others
    = note: required because of the requirements on the impl of `std::convert::Into<noria::data::DataType>` for `mysql_common::value::Value`
    = note: required because of the requirements on the impl of `std::convert::TryFrom<mysql_common::value::Value>` for `noria::data::DataType`

error[E0308]: mismatched types
   --> src/lib.rs:285:77
    |
285 |                 Err(e) => return Err(WriteProxyErr::MysqlToNoriaDatatypeErr(e)),
    |                                                                             ^ expected `&str`, found enum `std::convert::Infallible`

Meta

rustc 1.44.0-nightly (94d3463 2020-04-09)
binary: rustc
commit-hash: 94d3463
commit-date: 2020-04-09
host: x86_64-unknown-linux-gnu
release: 1.44.0-nightly
LLVM version: 9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-crate-version-mismatchDiagnostics: Errors or lints caused be the use of two different crate versions.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions