Search code examples
rustrust-cargo

How do determine which crate is using which version is a Cargo.lock file?


I'm trying to start up a project that uses an STM32, LVGL Rust bindings, and a Gc9a01. The LVGL binding provides a callback function that passes an DisplayRefresh object that has the area of the screen to render to, and a method called .into_pixels<C>() where C is the pixel color format, in this case Rgb565.

When I try to use the .into_pixels::<Rgb565>() function, the compiler provides a verbose message:

 --> src/main.rs:182:31
    |
182 |             display.draw_iter(refresh.as_pixels::<Rgb565>());
    |                     --------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Pixel<Rgb565>`, found a different `Pixel<Rgb565>`
    |                     |
    |                     required by a bound introduced by this call
    |
    = note: `Pixel<Rgb565>` and `Pixel<Rgb565>` have similar names, but are actually distinct types
note: `Pixel<Rgb565>` is defined in crate `embedded_graphics_core`
   --> /Users/myname/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embedded-graphics-core-0.3.3/src/drawable.rs:142:1
    |
142 | pub struct Pixel<C>(pub Point, pub C)
    | ^^^^^^^^^^^^^^^^^^^
note: `Pixel<Rgb565>` is defined in crate `embedded_graphics_core`
   --> /Users/myname/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embedded-graphics-core-0.4.0/src/drawable.rs:142:1
    |
142 | pub struct Pixel<C>(pub Point, pub C)
    | ^^^^^^^^^^^^^^^^^^^
    = note: perhaps two different versions of crate `embedded_graphics_core` are being used?
note: the method call chain might not have had the expected associated types
   --> src/main.rs:182:39
    |
182 |             display.draw_iter(refresh.as_pixels::<Rgb565>());
    |                               ------- ^^^^^^^^^^^^^^^^^^^^^ `IntoIterator::Item` is `Pixel<Rgb565>` here
    |                               |
    |                               this expression has type `&DisplayRefresh<2400>`
note: required by a bound in `draw_iter`
   --> /Users/myname/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embedded-graphics-core-0.4.0/src/draw_target/mod.rs:304:25
    |
302 |     fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
    |        --------- required by a bound in this associated function
303 |     where
304 |         I: IntoIterator<Item = Pixel<Self::Color>>;
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `DrawTarget::draw_iter`

It seems that there are different versions of embedded_graphics_core used in the project. The Cargo.lock file confirms this:

[[package]]
name = "embedded-graphics-core"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8b1239db5f3eeb7e33e35bd10bd014e7b2537b17e071f726a09351431337cfa"
dependencies = [
 "az",
 "byteorder",
]

[[package]]
name = "embedded-graphics-core"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba9ecd261f991856250d2207f6d8376946cd9f412a2165d3b75bc87a0bc7a044"
dependencies = [
 "az",
 "byteorder",
]

My issue is that I don't know how to track down which dependency has the conflict. The top-level Cargo.toml files for my immediate dependencies, the HAL, the LVGL Bindings, and the display driver are all using the same version of embedded-graphics-core.

TLDR - How do I track down a dependency or a dependency of a dependency that is using a certain version of an outdated library so I can go and fix the issue?

Thanks!


Solution

  • cargo tree -i embedded-graphics-core will print a tree of packages that depend on embedded-graphics-core, and you can see which version is required by which dependency of you.