{"id":"44d906890415256d","repo":"rust-lang/cargo","slug":"resolve-should-have-a-single-spec-with-resolved-fe","errorCode":null,"errorMessage":"resolve should have a single spec with resolved features","messagePattern":"resolve should have a single spec with resolved features","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/standard_lib.rs","lineNumber":111,"sourceCode":"    let dry_run = false;\n    let mut resolve = ops::resolve_ws_with_opts(\n        &std_ws,\n        target_data,\n        &build_config.requested_kinds,\n        &cli_features,\n        &specs,\n        HasDevUnits::No,\n        crate::resolver::features::ForceAllTargets::No,\n        dry_run,\n    )?;\n    debug_assert_eq!(resolve.specs_and_features.len(), 1);\n    Ok((\n        resolve.pkg_set,\n        resolve.targeted_resolve,\n        resolve\n            .specs_and_features\n            .pop()\n            .expect(\"resolve should have a single spec with resolved features\")\n            .resolved_features,\n    ))\n}\n\n/// Generates a map of root units for the standard library for each kind requested.\n///\n/// * `crates` is the arg value from `-Zbuild-std`.\n/// * `units` is the root units of the build.\npub fn generate_std_roots(\n    crates: &[String],\n    units: &[Unit],\n    std_resolve: &Resolve,\n    std_features: &ResolvedFeatures,\n    kinds: &[CompileKind],\n    package_set: &PackageSet<'_>,\n    interner: &UnitInterner,\n    profiles: &Profiles,\n    target_data: &RustcTargetData<'_>,","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/compiler/standard_lib.rs#L93-L129","documentation":"`resolve_std` pops the single resolved spec-and-features entry via `.pop().expect(\"resolve should have a single spec with resolved features\")`, guarded by a `debug_assert_eq!(resolve.specs_and_features.len(), 1)`. The standard library resolve is constructed for exactly one spec (the std workspace), so the vector must be non-empty. The panic indicates the resolver returned zero specs for std.","triggerScenarios":"Using `-Zbuild-std` with a crate list/config that yields no std packages; a resolver bug that returns an empty `specs_and_features`; a std workspace whose source is missing so resolution produces nothing (though normally that errors earlier).","commonSituations":"`-Zbuild-std` with a malformed `crates` argument (e.g. `-Zbuild-std=` with names that match no std crate); missing `rust-src` component combined with a resolver quirk; nightly Cargo with a `-Zbuild-std` regression.","solutions":["Re-check the `-Zbuild-std` argument (e.g. `-Zbuild-std=std,panic_abort`) and ensure the crate names are valid.","`rustup component add rust-src` so the std workspace resolves correctly.","Update nightly Cargo; `-Zbuild-std` semantics change frequently."],"exampleFix":"// before\nresolve\n    .specs_and_features\n    .pop()\n    .expect(\"resolve should have a single spec with resolved features\")\n    .resolved_features\n// after\nresolve\n    .specs_and_features\n    .into_iter()\n    .next()\n    .ok_or_else(|| anyhow::anyhow!(\"-Zbuild-std resolve produced no specs; check the -Zbuild-std crate list and rust-src\"))?\n    .resolved_features","handlingStrategy":"validation","validationCode":"// Validate the -Zbuild-std crate list against known std-workspace lib crates\nconst KNOWN_STD_CRATES: &[&str] = &[\"std\",\"core\",\"alloc\",\"proc_macro\",\"panic_abort\",\"panic_unwind\",\"compiler_builtins\"];\nfn valid_build_std(crates: &[String]) -> bool {\n    crates.iter().all(|c| KNOWN_STD_CRATES.contains(&c.as_str()))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the documented `-Zbuild-std=std,panic_abort` form.","Run `rustup component add rust-src`.","Match the nightly Cargo version to the rust-src you use."],"tags":["cargo","build-std","resolver","nightly","internal-invariant"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}