I have a crate in which cargo clippy says there are multiple versions of hashbrown. I wanted to check were they are pulled in, so I ran cargo tree, but there are no instances of hashbrown in the tree (at least, according to cargo tree).
I thought cargo tree would always list all dependencies. I can't find a single reference to hashbrown .. how can there be a version conflict?
cargo tree doesn’t list everything that might be used in every case by default. Try:
cargo tree --all-features --target=all --workspace --invert=hashbrown
If that doesn’t work (it should), you can always read the Cargo.lock file directly — searching for hashbrown will find all the packages that depend on hashbrown.
Interesting -- the magic sauce that makes hashbrown appear is the --invert=hashbrown (I can't see it with the other options), but doing this removes the context I was looking for, so I did the Cargo.lock spelunking as you suggested, and it looks like getrandom is pulling in waspip2 and wasip3, which end up pulling in different hashbrown versions. (At least, I think that's the culprit).
Key insights:
clippy's "multiple dependency versions" check "sees" things that plain cargo tree doesn't.
cargo tree isn't a pure dump of Cargo.lock. I don't where I got the idea that it is, but for some reason I've believed that for a long time.
If one wants to figure out what's actually causing clippy's "multiple crate versions" warnings, Cargo.lock is the way to go.
This is so weird. I doesn't list the packages that depend on hashbrown, it prints only this:
❯ cargo tree --all-features --target=all --workspace --invert=hashbrown
error: There are multiple `hashbrown` packages in your project, and the specification `hashbrown` is ambiguous.
Please re-run this command with one of the following specifications:
hashbrown@0.15.5
hashbrown@0.16.1
❯ cargo tree --all-features --target=all --workspace --invert="hashbrown@0.15.5"
warning: nothing to print.
❯ cargo tree --all-features --target=all --workspace --invert="hashbrown@0.16.1"
warning: nothing to print.
(Why the --invert parameter even matter is another discussion, it's still weird it doesn't show hashbrown when printing the whole tree without --invert)