Using two version of the same crate gives confusing message · Issue #109161 · rust-lang/rust (original) (raw)

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