diff --git a/src/cargo/core/compiler/build_config.rs b/src/cargo/core/compiler/build_config.rs index 4b488261ccf..bc829ef2ba2 100644 --- a/src/cargo/core/compiler/build_config.rs +++ b/src/cargo/core/compiler/build_config.rs @@ -69,6 +69,9 @@ impl BuildConfig { )?; } let jobs = jobs.or(cfg.jobs).unwrap_or(::num_cpus::get() as u32); + if jobs == 0 { + anyhow::bail!("jobs may not be 0"); + } Ok(BuildConfig { requested_kinds, diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 1dfc8d99437..fc11e666df0 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -4802,6 +4802,24 @@ fn good_cargo_config_jobs() { p.cargo("build -v").run(); } +#[cargo_test] +fn invalid_cargo_config_jobs() { + let p = project() + .file("src/lib.rs", "") + .file( + ".cargo/config", + r#" + [build] + jobs = 0 + "#, + ) + .build(); + p.cargo("build -v") + .with_status(101) + .with_stderr_contains("error: jobs may not be 0") + .run(); +} + #[cargo_test] fn invalid_jobs() { let p = project()