Skip to content

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

Closed
@njsmith

Description

@njsmith

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

Metadata

Metadata

Assignees

No one assigned

    Labels

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