[Solved] Cargo failed to select a version (not due to conflicts)

I have a project which has a dependency on pnet version 0.30.*, in Cargo.toml:

pnet = "0.30"

When I run cargo build on my Linux machine, the project builds normally. When I run cargo build on Windows I get this error:

> cargo build
    Updating crates.io index
error: failed to select a version for the requirement `pnet = "^0.30"`
candidate versions found which didn't match: 0.29.0, 0.28.0, 0.27.2, ...
location searched: crates.io index

I've tried deleting the Cargo registry (everything from %USERPROFILE%\.cargo except the bin folder) but that didn't make any difference. Running cargo build from a MinGW64 git bash prompt has the same error as in Powershell.

What could cause this and how do I work around it?

Does any of your other dependencies also depend on pnet?

No, not according to cargo tree.

Version 0.30 was released recently. My guess is that this is some sort of caching issues. You could try cargo update. Perhaps also try deleting Cargo.lock or target.

Just tried all that again, still no change unfortunately.

When I added pent = "0.30.0", it was built successfully. Will your network instability lead to errors in pulling dependencies

Of course, as Alice said, it may have something to do with caching

You were right it was to do with caching, after deleting my .cargo and .rustup directories then re-running rustup-init.exe and reinstalling the toolchain it started working again. My guess is that Cargo's clone of the crates.io repository wasn't updated, but I can't figure out where that's stored to reset it.

I just hit the same issue with the same crate & version which seemed unlikely to be a coincidence.

A little digging suggests that the trigger is this change in pnet version 0.30.0 to use the fairly new (Rust 1.60) dep-name?/feature-name syntax (see https://github.com/rust-lang/cargo/pull/10269).

In my case this was impacting cargo outdated -R as, ironically, my cargo-outdated was outdated! Installing the latest cargo-outdated fixed that problem.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.