"failed to select a version for the requirement `clap = "^4"`"

When I attempt to add a dependency on clap v4 or later, I get:

    Updating crates.io index
error: failed to sync

Caused by:
  failed to load pkg lockfile

Caused by:
  failed to select a version for the requirement `clap = "^4"`
  candidate versions found which didn't match: 3.2.25, 3.2.24, 3.2.23, ...
  location searched: crates.io index

This is at work, so Things Are Complicated™️; we're on a nightly version just before 1.63: rustc 1.63.0-nightly (fdca237d5 2022-06-24). But Clap v4.0.0 says its MSRV is 1.60, so we're well past that. Later v4 versions of clap have more restrictive MSRVs, up to v1.64; I don't expect cargo to choose those versions.

This is cargo local-registry emitting here, but I figure this is using the same internal logic as Cargo to do the version resolution.

Why are none of the v4.0.0 or later crates showing up here?

(I've also considered Rust editions: clap is 2021, but that was released in 1.56. Clap's Cargo.toml declares resolver v2, but that was made the default resolver in the 2021 edition.)

I'm going to answer my own question, I guess. I'm on cargo-local-registry v0.2.2, and this requires v0.2.3 or later. So close.

What was helpful in debugging this: first, set RUST_LOG=debug and then cargo local-registry will emit logs. That netted me,

[2023-07-21T20:50:19Z DEBUG cargo::sources::registry::index] unsupported schema version 2 (clap 4.0.3)

I had to dig into the cargo source code for that one, but one finds that the error message is emitted if the schema version is greater than "max_version", and that max_version is,

        let max_version = if namespaced_features || weak_dep_features {
        } else {

Those look to me like unstablized features. They're easy to find in the RFC book; from there, you get the Github issue for them, and from there you need to find the PR that stabilizes them (not the one that implements them, so look for where the PR is closed); then under the tags in Github you can see that first appears under 0.61.0. cargo tree on my version of cargo-local-registry tells me we have cargo v0.57.0, so, too old.

Then it's just a matter of finding a version of cargo-local-registry where the cargo dep is 0.61.0 or later, and that's easy, it's literally the next version.


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.