rust-lang/cargo · error

could not parse `{j}`. Number of parallel jobs should be `de

Error message

could not parse `{j}`. Number of parallel jobs should be `default` or a number.

What it means

In BuildConfig::new (build_config.rs:94-100), `jobs` can be the string `"default"` or an integer. If `build.jobs` (or `-j`) is set to any other string (e.g. `"auto"`, `"max"`, `"4 cores"`), parsing fails with `could not parse ... Number of parallel jobs should be 'default' or a number`.

Source

Thrown at src/compiler/build_config.rs:97

        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) => {
                gctx.shell()
                    .warn("ignoring 'sbom' config, pass `-Zsbom` to enable it")?;
                false
            }
            (None, _) => false,
        };

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Use an integer: `cargo build -j 8` or `[build] jobs = 8`.
  2. Use the literal string `default` to use the default parallelism.
  3. Remove the `jobs` setting to fall back to default parallelism.
  4. If you wanted `auto`, just omit `-j`.

Example fix

// before (.cargo/config.toml)
[build]
jobs = "auto"

// after
[build]
jobs = "default"
Defensive patterns

Strategy: validation

Validate before calling

match &jobs_config {
    JobsConfig::String(s) if s != "default" => {
        return Err(format!("jobs `{s}` must be a number or `default`"));
    }
    _ => {}
}

Type guard

fn jobs_string_valid(s: &str) -> bool {
    s == "default" || s.parse::<i64>().is_ok()
}

Prevention

When it happens

Trigger: Setting `[build] jobs = "auto"` in config, passing `cargo build -j auto`, or setting `CARGO_BUILD_JOBS=auto`.

Common situations: Users assuming Cargo accepts `auto`/`max`/`physical` (common in other tools); copying config from make/ninja; stale docs.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/79041acf8f9a18c0.json. Report an issue: GitHub.