rust-lang/cargo · error
jobs may not be 0
Error message
jobs may not be 0
What it means
BuildConfig::new resolves the parallel job count. When the resolved jobs value is the integer 0 (from -j 0 or build.jobs = 0 in config), it bails immediately with 'jobs may not be 0' because zero parallelism is invalid. Negative values are treated as relative to default parallelism; the literal 0 is forbidden.
Solutions
- Use a positive integer: `-j 4` or omit -j to use default parallelism.
- Use `-j default` (string) or a negative number (e.g. -j -1 reserves one core) for relative behavior.
- Ensure scripts never pass 0: default the variable to a positive value or empty.
Example fix
// before cargo build -j 0 // after cargo build -j 4 # or omit -j
Defensive patterns
Strategy: validation
Validate before calling
// Clamp jobs to >= 1 before invoking Cargo
let jobs = jobs_raw.max(1);
// or guard the config value
if let Some(0) = config.build.jobs { eprintln!("build.jobs must be > 0"); } Type guard
null
Try / catch
null
Prevention
- Never pass -j 0; default script variables to a positive integer or empty.
- Use 'default' or omit -j to let Cargo pick parallelism.
When it happens
Trigger: Passing `-j 0` on the command line, or setting `jobs = 0` / `jobs = 0` under `[build]` in config (.cargo/config.toml). The match arm for 0 bails before any build starts.
Common situations: CI scripts computing `-j` from a variable that can be 0; config templates defaulting jobs to 0; env-driven job counts (e.g. -j$VAR with VAR unset->0 via shell).
Related errors
- dependency ` ` in package ` ` requires a ` ` artifact to be…
- config.json not found
- could not parse ` `. Number of parallel jobs should be…
- couldn't find repository name
- couldn't find username
AI-assisted analysis of rust-lang/cargo@eb98b54bc9 (2026-08-11).
Data as JSON: /api/errors/9245a0ccadab6066.
Report an issue: GitHub.
Appendix: source
Thrown at src/compiler/build_config.rs:90
jobs: Option<JobsConfig>,
keep_going: bool,
requested_targets: &[String],
intent: UserIntent,
) -> CargoResult<BuildConfig> {
let cfg = gctx.build_config()?;
let requested_kinds = CompileKind::from_requested_targets(gctx, requested_targets)?;
if jobs.is_some() && gctx.jobserver_from_env().is_some() {
gctx.shell().warn(
"a `-j` argument was passed to Cargo but Cargo is \
also configured with an external jobserver in \
its environment, ignoring the `-j` parameter",
)?;
}
let jobs = match jobs.or(cfg.jobs.clone()) {
None => default_parallelism()?,
Some(value) => match value {
JobsConfig::Integer(j) => match j {
0 => anyhow::bail!("jobs may not be 0"),
j if j < 0 => (default_parallelism()? as i32 + j).max(1) as u32,
j => j as u32,
},
JobsConfig::String(j) => match j.as_str() {
"default" => default_parallelism()?,
_ => {
anyhow::bail!(format!(
"could not parse `{j}`. Number of parallel jobs should be `default` or a number."
))
}
},
},
};
// If sbom flag is set, it requires the unstable feature
let sbom = match (cfg.sbom, gctx.cli_unstable().sbom) {
(Some(sbom), true) => sbom,
(Some(_), false) => {View on GitHub (pinned to eb98b54bc9)