rust-lang/cargo · error · anyhow::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` at src/workspace/parser/mod.rs:1165. When `[lints] workspace = true` (inherit lints from `workspace.lints`) but the same `[lints]` table also defines local lint entries, cargo refuses to merge them silently — you must either inherit fully or specify lints manually. The guard is `lints.workspace && !lints.lints.is_empty()`.
Source
Thrown at src/workspace/parser/mod.rs:1165
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 0e07a15537)
Solutions
- Remove the local `[lints.<tool>]` entries so only `workspace = true` remains.
- Or drop `workspace = true` and manually specify every lint in the member.
Example fix
# before [lints] workspace = true [lints.rust] unsafe_code = "warn" # after (inherit fully) [lints] workspace = true # (move unsafe_code to [workspace.lints.rust] in the root)
Defensive patterns
Strategy: validation
Validate before calling
if let Some(lints) = doc.get("lints").and_then(|i| i.as_table_like()) {
let inherits = lints.get("workspace").and_then(|v| v.as_bool()) == Some(true);
let has_local = lints.iter().any(|(k, _)| k != "workspace");
if inherits && has_local {
return Err("cannot mix [lints] workspace=true with local lints".into());
}
} Prevention
- Decide upfront: inherit all lints or specify all lints locally — not both.
- Run `cargo check` after editing the `[lints]` table.
When it happens
Trigger: A member manifest with `[lints]\nworkspace = true\n[lints.rust]\nunsafe_code = "warn"` — both inheritance and a local override present.
Common situations: Enabling workspace lint inheritance then adding a one-off lint; merging configs during a refactor; copying a member manifest and leaving stale entries.
Related errors
- package `{}` cannot be tested because it requires dev-depend
- {}package(s) `{}` not found in workspace `{}`
- no library targets found in packages: {}
- found a virtual manifest at `{}` instead of a package manife
- you can't generate a lockfile for an empty workspace.
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/1b0a3089e711294a.json.
Report an issue: GitHub.