rust-lang/cargo · error · anyhow::Error
warnings are denied by `build.warnings` configuration
Error message
warnings are denied by `build.warnings` configuration
What it means
Thrown in cargo_fetch::fetch (src/ops/cargo_fetch.rs:88-92) when the `build.warnings` config is set to `deny` (WarningHandling::Deny) AND the dependency parse pass emitted lint warnings (parse_pass_output.lint_warning_count > 0). Cargo treats warnings as hard failures in this deny mode, so fetch aborts.
Source
Thrown at src/ops/cargo_fetch.rs:91
// If -Zbuild-std was passed, download dependencies for the standard library.
if let Some(crates) = &gctx.cli_unstable().build_std {
let (std_package_set, _, _) = standard_lib::resolve_std(
ws,
&mut data,
&build_config,
crates,
&build_config.requested_kinds,
)?;
packages.add_set(std_package_set);
}
packages.get_many(to_download)?;
crate::workspace::gc::auto_gc(gctx);
if ws.gctx().warning_handling()? == WarningHandling::Deny
&& parse_pass_output.lint_warning_count > 0
{
anyhow::bail!("warnings are denied by `build.warnings` configuration")
}
Ok((resolve, packages))
}
View on GitHub (pinned to 0e07a15537)
Solutions
- Inspect the preceding warning lines (they are printed before the bail) and fix or pin the dependency causing them.
- Temporarily relax to `warnings = "warn"` to fetch, then re-enable deny.
- Pin the offending dependency to an older version whose manifest is clean.
- Upgrade cargo/the dependency so the manifest warning is resolved upstream.
Example fix
# before (.cargo/config.toml or Cargo.toml [build]) [build] warnings = "deny" # after [build] warnings = "warn"
Defensive patterns
Strategy: validation
Validate before calling
// If warnings are denied, expect fetch to fail when deps emit warnings.
use cargo::util::config::WarningHandling;
fn fetch_will_strict(ws: &Workspace) -> bool {
ws.gctx().warning_handling().ok()
.map(|h| matches!(h, WarningHandling::Deny))
.unwrap_or(false)
} Type guard
fn warnings_denied(ws: &Workspace) -> bool {
matches!(ws.gctx().warning_handling(), Ok(WarningHandling::Deny))
} Try / catch
match ops::fetch(ws, &opts) {
Err(e) if e.to_string().contains("warnings are denied") => {
eprintln!("a dependency emitted a warning; relax build.warnings or pin the dep");
return Err(e);
}
r => r,
} Prevention
- Use build.warnings = "warn" for fetch-heavy steps in CI.
- Pin dependencies whose manifests are warning-clean.
When it happens
Trigger: Configuring `[build] warnings = "deny"` (or equivalent env) and running `cargo fetch` when one or more resolved dependencies' manifests/parse produce warnings (e.g. deprecated manifest keys, yanked notices, unused fields).
Common situations: Strict CI that denies all warnings; a newly published dependency introduces a manifest warning. Upgrading cargo surfaces previously-suppressed warnings under deny mode. A `[build] warnings` setting copied from a template.
Related errors
- warnings are denied by `build.warnings` configuration
- subcommand is required, add a subcommand to the command alia
- alias {} has unresolvable recursive definition: {} -> {}
- subcommand is required, but `{alias_name}` is empty
- jobs may not be 0
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/31b33ab44f7e05a0.json.
Report an issue: GitHub.