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

If two crates have the same name, distinguish them in rustc's output? #110926

Closed
njsmith opened this issue Apr 28, 2023 · 1 comment · Fixed by #128786
Closed

If two crates have the same name, distinguish them in rustc's output? #110926

njsmith opened this issue Apr 28, 2023 · 1 comment · Fixed by #128786
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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

@njsmith
Copy link

njsmith commented Apr 28, 2023

Code

I'm writing code that uses the py-spy and remoteprocess crates. py-spy also uses remoteprocess internally. I tried to switch to using a different version of remoteprocess with some patches, but I foolishly did this by changing my top-level crate to depend on remoteprocess = { git = ... }, when what I really wanted was to use a [patch.crates-io] stanza. Anyway, the end result is that I had two different remoteprocess crates in my dependency tree without knowing it, and rustc gave me some spectacularly confusing errors. In particular, in a single message output, it suggested to try adding the line use remoteprocess::SomeTrait, and also suggested removing the line use remoteprocess::SomeTrait because it was unused.

Current output

error[E0599]: no method named `copy` found for struct `Process` in the current scope
   --> src/shmem.rs:273:22
    |
273 |                     .copy(current.metadata.name_ptr, current.metadata.name_len)?;
    |                      ^^^^ method not found in `Process`
    |
   ::: /Users/njs/.cargo/registry/src/github.com-1ecc6299db9ec823/remoteprocess-0.4.11/src/lib.rs:170:8
    |
170 |     fn copy(&self, addr: usize, length: usize) -> Result<Vec<u8>, Error> {
    |        ---- the method is available for `remoteprocess::osx::Process` here
    |
    = 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 remoteprocess::ProcessMemory;
    |

warning: unused import: `remoteprocess::ProcessMemory`
 --> src/shmem.rs:5:5
  |
5 | use remoteprocess::ProcessMemory;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

Desired output

It'd be nice if rustc detected this case and printed something hinting at what's going on?

Rationale and extra context

No response

Other cases

No response

Anything else?

No response

@njsmith njsmith 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 Apr 28, 2023
@jyn514 jyn514 added the D-crate-version-mismatch Diagnostics: Errors or lints caused be the use of two different crate versions. label Apr 28, 2023
@andresovela
Copy link

#81659 is related and not labeled as D-crate-version-mismatch

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-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.

3 participants