Skip to content

Confusing diagnostics when pulling the same crate from different sources #81659

Closed
@andresovela

Description

@andresovela

Source thread in URLO

I was working with a library crate that I forked to modify locally in my project. In the Cargo.toml of the binary I referenced my local copy of the modified library, but the Cargo.toml of the modified library still referenced the crates.io version.

cargo tree output looks like this (truncated):

├── display-interface v0.4.0 (/Users/andresovela/dev/rust/embedded/my-app/crates/display-interface)
├── display-interface-parallel-gpio v0.4.1 (/Users/andresovela/dev/rust/embedded/my-app/crates/display-interface/parallel-gpio)
│   ├── byte-slice-cast v0.3.5
│   ├── display-interface v0.4.0
├── ili9486 v0.1.0 (/Users/andresovela/dev/rust/embedded/my-app/crates/ili9486-rs)
│   ├── display-interface v0.4.0 (/Users/andresovela/dev/rust/embedded/my-app/crates/display-interface)
│   ├── display-interface-parallel-gpio v0.4.1 (/Users/andresovela/dev/rust/embedded/my-app/crates/display-interface/parallel-gpio) (*)

The problem being that the Cargo.toml in display-interface-parallel-gpio was referencing the crates.io version of display-interface instead of my local copy.

This resulted in the compiler giving me the following error and warning:

error[E0599]: no method named `send_commands` found for struct `PGPIO8BitInterface<nrf52832_hal::gpio::Pin<Output<PushPull>>, P0_28<Output<PushPull>>, P0_04<Output<PushPull>>>` in the current scope
  --> src/main.rs:44:23
   |
44 |     ili9486_interface.send_commands(display_interface::DataFormat::U8(&data));
   |                       ^^^^^^^^^^^^^ method not found in `PGPIO8BitInterface<nrf52832_hal::gpio::Pin<Output<PushPull>>, P0_28<Output<PushPull>>, P0_04<Output<PushPull>>>`
   |
   = 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:
   |
4  | use display_interface::WriteOnlyDataCommand;
   |

warning: unused import: `display_interface::WriteOnlyDataCommand`
 --> src/main.rs:4:5
  |
4 | use display_interface::WriteOnlyDataCommand;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It would have been much much better if the compiler noticed that there is conflict in crate versions somehow. Maybe if it detects that the trait name exists but it comes from a different crate or something? Unfortunately I'm not well versed in the compiler internals, but I think this case could be definitely improved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-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