I have a project which has a dependency on pnet version 0.30.*, in Cargo.toml:
[dependencies]
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?
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.
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.