rust-lang/cargo · error

cannot override `workspace.lints` in `lints`, either remove…

Error message

cannot override `workspace.lints` in `lints`, either remove the overrides or `lints.workspace = true` and manually specify the lints

What it means

Thrown by lints_inherit_with when the [lints] table sets workspace = true AND simultaneously defines specific lints. Cargo treats these as mutually exclusive: either inherit all lints from the workspace or specify them locally. Mixing produces ambiguous precedence, so the parser rejects it outright with guidance to choose one strategy.

Solutions

  1. Remove the local lint entries and rely solely on the workspace's [workspace.lints] definition.
  2. Or set lints.workspace = false (or remove it) and manually specify every lint you need locally.
  3. To customize, edit the workspace root's [workspace.lints] so all members inherit the change.

Example fix

# before
[lints]
workspace = true

[lints.rust]
unsafe_code = "forbid"  # conflicts with workspace inheritance

# after (option A: inherit only)
[lints]
workspace = true

# after (option B: local only)
[lints.rust]
unsafe_code = "forbid"
Defensive patterns

Strategy: validation

Validate before calling

fn lints_inherit_is_consistent(toml: &str) -> Result<(), String> {
    let v: toml::Value = toml::from_str(toml).map_err(|e| e.to_string())?;
    if let Some(lints) = v.get("lints").and_then(|l| l.as_table()) {
        let workspace_true = lints.get("workspace").and_then(|w| w.as_bool()) == Some(true);
        let has_local = lints.keys().any(|k| k != "workspace");
        if workspace_true && has_local {
            return Err("cannot set lints.workspace = true and define local lints".into());
        }
    }
    Ok(())
}

Type guard

fn lints_config_is_valid(lints: &toml::value::Table) -> bool {
    let ws = lints.get("workspace").and_then(|w| w.as_bool()) == Some(true);
    let local = lints.keys().any(|k| k != "workspace");
    !(ws && local)
}

Prevention

When it happens

Trigger: A manifest contains [lints] with both 'workspace = true' and one or more lint entries, e.g. [lints.workspace] = true alongside [lints.rust] dead_code = 'warn'. lints.workspace is true and lints.lints is non-empty.

Common situations: A developer starts with workspace lints then tries to override a single lint locally. A merge tool combines two manifest edits, one adding workspace=true and another adding a lint. Copy-pasting a lint config into a workspace-inheriting package.

Related errors


AI-assisted analysis of rust-lang/cargo@98a09e7e7d (2026-08-11). Data as JSON: /api/errors/1b0a3089e711294a. Report an issue: GitHub.

Appendix: source

Thrown at src/workspace/parser/mod.rs:1164

    get_ws_inheritable: impl FnOnce() -> CargoResult<T>,
) -> CargoResult<T> {
    match field {
        manifest::InheritableField::Value(value) => Ok(value),
        manifest::InheritableField::Inherit(_) => get_ws_inheritable().with_context(|| {
            format!(
                "error inheriting `{label}` from workspace root manifest's `workspace.package.{label}`",
            )
        }),
    }
}

fn lints_inherit_with(
    lints: manifest::InheritableLints,
    get_ws_inheritable: impl FnOnce() -> CargoResult<manifest::TomlLints>,
) -> CargoResult<manifest::TomlLints> {
    if lints.workspace {
        if !lints.lints.is_empty() {
            anyhow::bail!(
                "cannot override `workspace.lints` in `lints`, either remove the overrides or `lints.workspace = true` and manually specify the lints"
            );
        }
        get_ws_inheritable().with_context(
            || "error inheriting `lints` from workspace root manifest's `workspace.lints`",
        )
    } else {
        Ok(lints.lints)
    }
}

fn dependency_inherit_with<'a>(
    dependency: manifest::InheritableDependency,
    name: &str,
    inherit: &dyn Fn() -> CargoResult<&'a InheritableFields>,
    package_root: &Path,
    edition: Edition,
    warnings: &mut Vec<String>,

View on GitHub (pinned to 98a09e7e7d)