{"id":"0073958a026a648e","repo":"rust-lang/cargo","slug":"we-ve-already-checked-that-there-is-exactly-one","errorCode":null,"errorMessage":"We've already checked that there is exactly one.","messagePattern":"We've already checked that there is exactly one\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/ops/cargo_fix/mod.rs","lineNumber":628,"sourceCode":"        let feature_opts = FeatureOpts::new_behavior(ResolveBehavior::V2, has_dev_units);\n        let v2_features = FeatureResolver::resolve(\n            ws,\n            target_data,\n            &ws_resolve.targeted_resolve,\n            &ws_resolve.pkg_set,\n            &opts.compile_opts.cli_features,\n            &specs,\n            &opts.compile_opts.build_config.requested_kinds,\n            feature_opts,\n        )?;\n\n        if ws_resolve.specs_and_features.len() != 1 {\n            bail!(r#\"cannot fix edition when using `feature-unification = \"package\"`.\"#);\n        }\n        let resolved_features = &ws_resolve\n            .specs_and_features\n            .first()\n            .expect(\"We've already checked that there is exactly one.\")\n            .resolved_features;\n        let diffs = v2_features.compare_legacy(resolved_features);\n        Ok((ws_resolve, diffs))\n    };\n    let (_, without_dev_diffs) = resolve_differences(HasDevUnits::No)?;\n    let (ws_resolve, mut with_dev_diffs) = resolve_differences(HasDevUnits::Yes)?;\n    if without_dev_diffs.is_empty() && with_dev_diffs.is_empty() {\n        // Nothing is different, nothing to report.\n        return Ok(());\n    }\n    // Only display unique changes with dev-dependencies.\n    with_dev_diffs.retain(|k, vals| without_dev_diffs.get(k) != Some(vals));\n    let gctx = ws.gctx();\n    gctx.shell().note(\n        \"Switching to Edition 2021 will enable the use of the version 2 feature resolver in Cargo.\",\n    )?;\n    drop_eprintln!(\n        gctx,","sourceCodeStart":610,"sourceCodeEnd":646,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_fix/mod.rs#L610-L646","documentation":"This is an internal invariant panic in cargo's edition-fix logic. After `resolve_differences` verifies that `ws_resolve.specs_and_features.len() == 1` (bailing otherwise at line 622-624 for the `feature-unification = \"package\"` case), it calls `.first().expect(...)`. The expect fires only if `specs_and_features` is somehow empty despite passing the length check, which cannot happen under normal control flow.","triggerScenarios":"Running `cargo fix --edition` (or `cargo fix --features` resolution diagnostics) in a workspace configured with `resolver.feature-unification = \"package\"` (or the equivalent unstable flag) where `WorkspaceResolve::specs_and_features` ends up empty. Concretely the `.first()` on a zero-length Vec yields `None`.","commonSituations":"A bug in cargo's feature resolver producing zero specs where one is expected; mixing the new `feature-unification = \"package\"` unstable option with edge-case workspace layouts (virtual manifests, no members resolved, exotic `[features]`); running a custom cargo build with patches to the resolve pipeline.","solutions":["Report a bug at https://github.com/rust-lang/cargo/issues with the workspace manifest and exact `cargo fix` invocation; this is a cargo internal assertion, not a user-config error.","Temporarily remove `feature-unification = \"package\"` (or the `-Z` flag enabling it) and re-run `cargo fix --edition` to confirm the panic is gated on that resolver mode.","Upgrade or downgrade cargo (rustup) to a version without the regression — check the CHANGELOG for resolver/fix patches.","Reproduce with `cargo fix --edition -vv` and capture the backtrace (`RUST_BACKTRACE=full`) to attach to the issue."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before invoking edition-fix resolution, confirm the workspace resolves to exactly one spec.\nlet specs_count = ws_resolve.specs_and_features.len();\nassert!(specs_count == 1, \"expected exactly one spec, got {}\", specs_count);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid `feature-unification = \"package\"` (and the matching -Z flag) until it stabilizes.","Pin cargo to a known-good toolchain in CI (`rust-toolchain.toml`).","Run `cargo fix --edition` on a clean checkout and review resolver warnings before adopting new resolver options."],"tags":["cargo","panic","invariant","resolver","fix-edition","rust"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}