rust-lang/cargo · error

as `None` are compatible, we can't be here

Error message

as `None` are compatible, we can't be here

What it means

This panic is in get_latest_dependency() within the MSRV (minimum supported Rust version) compatibility check. When latest_compatible() returns None (no version satisfies the required rust-version), the error closure calls latest.rust_version().expect("as `None` are compatible, we can't be here"). The invariant is that candidates with rust_version() == None are treated as always-compatible by latest_compatible(), so if none are compatible, the latest candidate must have had a concrete rust_version (Some).

Source

Thrown at src/ops/cargo_add/mod.rs:921

                        Ok((rustc_version, false))
                    })?;

                let msrvs = possibilities
                    .iter()
                    .map(|s| (s, s.rust_version()))
                    .collect::<Vec<_>>();

                // Find the latest version of the dep which has a compatible rust-version. To
                // determine whether or not one rust-version is compatible with another, we
                // compare the lowest possible versions they could represent, and treat
                // candidates without a rust-version as compatible by default.
                let latest_msrv = latest_compatible(&msrvs, &req_msrv).ok_or_else(|| {
                        let name = spec.name();
                        let dep_name = &dependency.name;
                        let latest_version = latest.version();
                        let latest_msrv = latest
                            .rust_version()
                            .expect("as `None` are compatible, we can't be here");
                        if is_msrv {
                            anyhow::format_err!(
                                "\
no version of crate `{dep_name}` can maintain {name}'s rust-version of {req_msrv}
help: pass `--ignore-rust-version` to select {dep_name}@{latest_version} which requires rustc {latest_msrv}"
                            )
                        } else {
                            anyhow::format_err!(
                                "\
no version of crate `{dep_name}` is compatible with rustc {req_msrv}
help: pass `--ignore-rust-version` to select {dep_name}@{latest_version} which requires rustc {latest_msrv}"
                            )
                        }
                    })?;

                if latest_msrv.version() < latest.version() {
                    let latest_version = latest.version();
                    let latest_rust_version = latest.rust_version().unwrap();

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Pass --ignore-rust-version to bypass the MSRV check: cargo add <crate> --ignore-rust-version.
  2. Upgrade your Rust toolchain to match the dependency's requirements.
  3. Pin to a specific older version that supports your MSRV: cargo add <crate>@<older-version>.
  4. Update cargo — latest_compatible() filtering bugs are patched in point releases.

Example fix

# before
cargo add some-crate
# after (bypass MSRV check or pin version)
cargo add some-crate --ignore-rust-version
cargo add some-crate@0.5.0
Defensive patterns

Strategy: validation

Validate before calling

// Check your rustc version before cargo add
cargo check --offline 2>&1 | grep "rustc"
// Or verify MSRV compatibility before adding
rustc --version

Prevention

When it happens

Trigger: Adding a dependency where the latest version requires a newer Rust than your MSRV, and every candidate version either has a conflicting rust-version or the latest_compatible algorithm has a bug where it skips a None-rust-version candidate that should have matched.

Common situations: Running cargo add with an old rustc/MSRV against a crate whose all published versions declare incompatible rust-version fields; a cargo bug in latest_compatible() that misfilters None-rust-version candidates; using --ignore-rust-version incorrectly.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/f7672641b6906820.json. Report an issue: GitHub.