How to improve errors due to multiple crate versions in the dependency graph?


While playing around with the latest instalment of ArcadeRS I made an error in specifying the dependency versions, which led to multiple versions of sdl2 being pulled in by the sdl2, sdl2_image, sdl2_ttf and sdl2_mixer dependencies (0.15 and 0.16 I think).

Now sdl2_image defines a trait called LoadTexture and implements it on sdl2’s Renderer, so that you can say renderer.load_texture(...). The code is using this method, and after the dependency update stopped working with (other errors appeared, but were real API changes and fixable)

error: the trait `sdl2_image::LoadTexture` is not implemented for the type
`sdl2::render::Renderer<'_>` [E0277]

which is very confusing until you find out that there are two Renderers in your build. (cargo list --tree helps enormously once you know what to look for.)

Does rustc have any way of recognizing this situation, and displaying some hint to the user about the same type coming from multiple crate versions?


I think that while rustc may present a better error message here, the better solution is to detect such inconsistencies in cargo. Here is the relevant discussion: