{"id":"7e3b52597eb2a200","repo":"rust-lang/cargo","slug":"warnings-are-denied-by-build-warnings-configurat","errorCode":null,"errorMessage":"warnings are denied by `build.warnings` configuration","messagePattern":"warnings are denied by `build\\.warnings` configuration","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_compile/mod.rs","lineNumber":154,"sourceCode":"\n/// Like [`compile`] but allows specifying a custom [`Executor`]\n/// that will be able to intercept build calls and add custom logic.\n///\n/// [`compile`] uses [`DefaultExecutor`] which just passes calls through.\npub fn compile_with_exec<'a>(\n    ws: &Workspace<'a>,\n    options: &CompileOptions,\n    exec: &Arc<dyn Executor>,\n) -> CargoResult<Compilation<'a>> {\n    let parse_pass_output = crate::diagnostics::passes::emit_parse_diagnostics(\n        ws,\n        crate::diagnostics::rules::PARSE_PASS_RULES,\n    )?;\n    let compilation = compile_ws(ws, options, exec)?;\n    if ws.gctx().warning_handling()? == WarningHandling::Deny\n        && (compilation.lint_warning_count + parse_pass_output.lint_warning_count) > 0\n    {\n        anyhow::bail!(\"warnings are denied by `build.warnings` configuration\")\n    }\n    Ok(compilation)\n}\n\n/// Like [`compile_with_exec`] but without warnings from manifest parsing.\n#[tracing::instrument(skip_all)]\nfn compile_ws<'a>(\n    ws: &Workspace<'a>,\n    options: &CompileOptions,\n    exec: &Arc<dyn Executor>,\n) -> CargoResult<Compilation<'a>> {\n    let interner = UnitInterner::new();\n    let logger = BuildLogger::maybe_new(ws, &options.build_config)?;\n\n    if let Some(ref logger) = logger {\n        let rustc = ws.gctx().load_global_rustc(Some(ws))?;\n        let num_cpus = std::thread::available_parallelism()\n            .ok()","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_compile/mod.rs#L136-L172","documentation":"When `build.warnings = \"deny\"` is set in cargo configuration, any compile/build operation that emits even one warning (counted from both the parse pass and the actual compilation) is turned into a hard failure. After `compile_ws` returns, `compile_with_exec` checks `warning_handling() == Deny` and, if the combined warning count is non-zero, bails with this message.","triggerScenarios":"Building with `[build] warnings = \"deny\"` (or the equivalent config/env) while the code or manifest produces warnings — e.g. unused imports, deprecated API usage, or manifest lint warnings.","commonSituations":"Strict CI configs that enforce zero-warning builds; a dependency upgrade or refactor that introduces new warnings; manifest parse warnings from deprecated fields.","solutions":["Fix the underlying warning(s) — the build output preceding the error lists each one; address them in source or manifest.","Temporarily relax the policy by setting `warnings = \"warn\"` (or removing the key) in `[build]` for the offending profile.","For a one-off, run with the warning allowed, e.g. via an override config or `--config` flag, then restore `deny`."],"exampleFix":"# before (.cargo/config.toml)\n[build]\nwarnings = \"deny\"\n# build fails on any warning\n\n# after (fix the warning, or relax)\n[build]\nwarnings = \"warn\"","handlingStrategy":"validation","validationCode":"// If build.warnings = \"deny\", ensure zero warnings before committing/building in CI.\n// Run a lint pass first and count warnings:\n//   cargo build 2> warnings.txt\n//   if [ -s warnings.txt ]; then exit 1; fi\n// Equivalent: gate on `cargo clippy -- -D warnings` before the deny-enabled build.","typeGuard":null,"tryCatchPattern":"// Differentiate deny-induced failures from real compile errors by checking the config.\nlet handling = ws.gctx().warning_handling()?;\nmatch ops::compile_with_exec(&ws, &opts, &exec) {\n    Ok(_) => Ok(()),\n    Err(e) if handling == WarningHandling::Deny && e.to_string().contains(\"warnings are denied\") => {\n        eprintln!(\"build aborted due to denied warnings; fix warnings or relax build.warnings\");\n        Err(e)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Gate CI on `cargo clippy -- -D warnings` so warnings fail early and visibly.","Keep `build.warnings = \"deny\"` only in branches you intend to keep warning-free.","Treat manifest deprecation warnings as part of the lint surface, not noise."],"tags":["cargo-build","warnings","lint","config"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}