Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
simon-friedberger opened this issue Mar 15, 2023 · 0 comments · Fixed by #128786
Closed

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

simon-friedberger opened this issue Mar 15, 2023 · 0 comments · Fixed by #128786
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-crate-version-mismatch Diagnostics: Errors or lints caused be the use of two different crate versions. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@simon-friedberger
Copy link

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

@simon-friedberger simon-friedberger added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 15, 2023
@WaffleLapkin WaffleLapkin added D-confusing Diagnostics: Confusing error or lint that should be reworked. D-crate-version-mismatch Diagnostics: Errors or lints caused be the use of two different crate versions. labels Mar 30, 2023
tgross35 added a commit to tgross35/rust that referenced this issue Aug 17, 2024
…r=fee1-dead

Detect multiple crate versions on method not found

When a type comes indirectly from one crate version but the imported trait comes from a separate crate version, the called method won't be found. We now show additional context:

```
error[E0599]: no method named `foo` found for struct `dep_2_reexport::Type` in the current scope
 --> multiple-dep-versions.rs:8:10
  |
8 |     Type.foo();
  |          ^^^ method not found in `Type`
  |
note: there are multiple different versions of crate `dependency` in the dependency graph
 --> multiple-dep-versions.rs:4:32
  |
4 | use dependency::{do_something, Trait};
  |                                ^^^^^ `dependency` imported here doesn't correspond to the right crate version
  |
 ::: ~/rust/build/x86_64-unknown-linux-gnu/test/run-make/crate-loading/rmake_out/multiple-dep-versions-1.rs:4:1
  |
4 | pub trait Trait {
  | --------------- this is the trait that was imported
  |
 ::: ~/rust/build/x86_64-unknown-linux-gnu/test/run-make/crate-loading/rmake_out/multiple-dep-versions-2.rs:4:1
  |
4 | pub trait Trait {
  | --------------- this is the trait that is needed
5 |     fn foo(&self);
  |        --- the method is available for `dep_2_reexport::Type` here
```

Fix rust-lang#128569, fix rust-lang#110926, fix rust-lang#109161, fix rust-lang#81659, fix rust-lang#51458, fix rust-lang#32611. Follow up to rust-lang#124944.
tgross35 added a commit to tgross35/rust that referenced this issue Aug 17, 2024
…r=fee1-dead

Detect multiple crate versions on method not found

When a type comes indirectly from one crate version but the imported trait comes from a separate crate version, the called method won't be found. We now show additional context:

```
error[E0599]: no method named `foo` found for struct `dep_2_reexport::Type` in the current scope
 --> multiple-dep-versions.rs:8:10
  |
8 |     Type.foo();
  |          ^^^ method not found in `Type`
  |
note: there are multiple different versions of crate `dependency` in the dependency graph
 --> multiple-dep-versions.rs:4:32
  |
4 | use dependency::{do_something, Trait};
  |                                ^^^^^ `dependency` imported here doesn't correspond to the right crate version
  |
 ::: ~/rust/build/x86_64-unknown-linux-gnu/test/run-make/crate-loading/rmake_out/multiple-dep-versions-1.rs:4:1
  |
4 | pub trait Trait {
  | --------------- this is the trait that was imported
  |
 ::: ~/rust/build/x86_64-unknown-linux-gnu/test/run-make/crate-loading/rmake_out/multiple-dep-versions-2.rs:4:1
  |
4 | pub trait Trait {
  | --------------- this is the trait that is needed
5 |     fn foo(&self);
  |        --- the method is available for `dep_2_reexport::Type` here
```

Fix rust-lang#128569, fix rust-lang#110926, fix rust-lang#109161, fix rust-lang#81659, fix rust-lang#51458, fix rust-lang#32611. Follow up to rust-lang#124944.
@bors bors closed this as completed in 9b318d2 Aug 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-crate-version-mismatch Diagnostics: Errors or lints caused be the use of two different crate versions. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants