{"id":"f7672641b6906820","repo":"rust-lang/cargo","slug":"as-none-are-compatible-we-can-t-be-here","errorCode":null,"errorMessage":"as `None` are compatible, we can't be here","messagePattern":"as `None` are compatible, we can't be here","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ops/cargo_add/mod.rs","lineNumber":921,"sourceCode":"                        Ok((rustc_version, false))\n                    })?;\n\n                let msrvs = possibilities\n                    .iter()\n                    .map(|s| (s, s.rust_version()))\n                    .collect::<Vec<_>>();\n\n                // Find the latest version of the dep which has a compatible rust-version. To\n                // determine whether or not one rust-version is compatible with another, we\n                // compare the lowest possible versions they could represent, and treat\n                // candidates without a rust-version as compatible by default.\n                let latest_msrv = latest_compatible(&msrvs, &req_msrv).ok_or_else(|| {\n                        let name = spec.name();\n                        let dep_name = &dependency.name;\n                        let latest_version = latest.version();\n                        let latest_msrv = latest\n                            .rust_version()\n                            .expect(\"as `None` are compatible, we can't be here\");\n                        if is_msrv {\n                            anyhow::format_err!(\n                                \"\\\nno version of crate `{dep_name}` can maintain {name}'s rust-version of {req_msrv}\nhelp: pass `--ignore-rust-version` to select {dep_name}@{latest_version} which requires rustc {latest_msrv}\"\n                            )\n                        } else {\n                            anyhow::format_err!(\n                                \"\\\nno version of crate `{dep_name}` is compatible with rustc {req_msrv}\nhelp: pass `--ignore-rust-version` to select {dep_name}@{latest_version} which requires rustc {latest_msrv}\"\n                            )\n                        }\n                    })?;\n\n                if latest_msrv.version() < latest.version() {\n                    let latest_version = latest.version();\n                    let latest_rust_version = latest.rust_version().unwrap();","sourceCodeStart":903,"sourceCodeEnd":939,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_add/mod.rs#L903-L939","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass --ignore-rust-version to bypass the MSRV check: cargo add <crate> --ignore-rust-version.","Upgrade your Rust toolchain to match the dependency's requirements.","Pin to a specific older version that supports your MSRV: cargo add <crate>@<older-version>.","Update cargo — latest_compatible() filtering bugs are patched in point releases."],"exampleFix":"# before\ncargo add some-crate\n# after (bypass MSRV check or pin version)\ncargo add some-crate --ignore-rust-version\ncargo add some-crate@0.5.0","handlingStrategy":"validation","validationCode":"// Check your rustc version before cargo add\ncargo check --offline 2>&1 | grep \"rustc\"\n// Or verify MSRV compatibility before adding\nrustc --version","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Know your MSRV and the target crate's rust-version before running cargo add.","Use --ignore-rust-version when you intentionally want a newer-rustc dependency.","Pin to a specific version that supports your MSRV: cargo add <crate>@<version>."],"tags":["rust","cargo","panic","invariant","cargo-add","msrv","rust-version"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}