rust-lang/cargo · error
resolve should have a single spec with resolved features
Error message
resolve should have a single spec with resolved features
What it means
`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.
Source
Thrown at src/compiler/standard_lib.rs:111
let dry_run = false;
let mut resolve = ops::resolve_ws_with_opts(
&std_ws,
target_data,
&build_config.requested_kinds,
&cli_features,
&specs,
HasDevUnits::No,
crate::resolver::features::ForceAllTargets::No,
dry_run,
)?;
debug_assert_eq!(resolve.specs_and_features.len(), 1);
Ok((
resolve.pkg_set,
resolve.targeted_resolve,
resolve
.specs_and_features
.pop()
.expect("resolve should have a single spec with resolved features")
.resolved_features,
))
}
/// Generates a map of root units for the standard library for each kind requested.
///
/// * `crates` is the arg value from `-Zbuild-std`.
/// * `units` is the root units of the build.
pub fn generate_std_roots(
crates: &[String],
units: &[Unit],
std_resolve: &Resolve,
std_features: &ResolvedFeatures,
kinds: &[CompileKind],
package_set: &PackageSet<'_>,
interner: &UnitInterner,
profiles: &Profiles,
target_data: &RustcTargetData<'_>,View on GitHub (pinned to 0e07a15537)
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.
Example fix
// before
resolve
.specs_and_features
.pop()
.expect("resolve should have a single spec with resolved features")
.resolved_features
// after
resolve
.specs_and_features
.into_iter()
.next()
.ok_or_else(|| anyhow::anyhow!("-Zbuild-std resolve produced no specs; check the -Zbuild-std crate list and rust-src"))?
.resolved_features Defensive patterns
Strategy: validation
Validate before calling
// Validate the -Zbuild-std crate list against known std-workspace lib crates
const KNOWN_STD_CRATES: &[&str] = &["std","core","alloc","proc_macro","panic_abort","panic_unwind","compiler_builtins"];
fn valid_build_std(crates: &[String]) -> bool {
crates.iter().all(|c| KNOWN_STD_CRATES.contains(&c.as_str()))
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: `-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.
Related errors
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/44d906890415256d.json.
Report an issue: GitHub.