Skip to content

Using two version of the same crate gives confusing message #109161

Closed
@simon-friedberger

Description

@simon-friedberger

Code

// main.rs
use prio::codec::Decode;
 
use janus_messages::HpkeConfig;
 
fn main() {
    let foo = [0u8; 100];
    HpkeConfig::get_decoded(&foo);
}
 
// Cargo.toml
[package]
name = "dap-test"
version = "0.1.0"
edition = "2021"
 
[dependencies]
janus_messages = "0.3.1" # note this depends on prio 0.10!
prio = "0.9.1"

Current output

error[E0599]: no function or associated item named `get_decoded` found for struct `HpkeConfig` in the current scope
 --> src/main.rs:7:17
  |
7 |     HpkeConfig::get_decoded(&foo);
  |                 ^^^^^^^^^^^ function or associated item not found in `HpkeConfig`
  |
  = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
  |
1 | use prio::codec::Decode;
  |

warning: unused import: `prio::codec::Decode`
 --> src/main.rs:1:5
  |
1 | use prio::codec::Decode;
  |     ^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

For more information about this error, try `rustc --explain E0599`.

Desired output

error[E0599]: no function or associated item named `get_decoded` found for struct `HpkeConfig` in the current scope
 --> src/main.rs:7:17
  |
7 |     HpkeConfig::get_decoded(&foo);
  |                 ^^^^^^^^^^^ function or associated item not found in `HpkeConfig`
  |
  = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
  |
1 | use prio(0.10.0)::codec::Decode;
  |

warning: unused import: `prio::codec::Decode`
 --> src/main.rs:1:5
  |
1 | use prio(0.9.1)::codec::Decode;
  |     ^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

For more information about this error, try `rustc --explain E0599`.

(#IIUC: Include the version number that causes those two Decode objects to be different.)

Rationale and extra context

Afaiu this is caused by a impl TraitFoo for StructBar in CrateBar which depends on CrateFoo (which has the trait) and then trying to use a function on TraitFoo on a StructBar from the main project which depends on a different version of CrateFoo. In that case it would help to add the version number.

Other cases

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-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.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