rust-lang/cargo · error · anyhow::Error

`default-features = false` cannot override workspace's `defa

Error message

`default-features = false` cannot override workspace's `default-features`

What it means

Thrown by `deprecated_ws_default_features` at src/workspace/parser/mod.rs:1274. In edition 2024 and later, a member dependency that inherits from `workspace.dependencies` is no longer allowed to override `default-features = false`, because that contradicts the workspace's decision and the resolution was made stricter. Before 2024 this is only a warning; from 2024 it is a hard error (`Edition::Edition2024 <= edition`).

Source

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

    };
    merged_dep.optional = *optional;
    merged_dep.public = *public;
    Ok(manifest::TomlDependency::Detailed(merged_dep))
}

fn deprecated_ws_default_features(
    label: &str,
    ws_def_feat: Option<bool>,
    edition: Edition,
    warnings: &mut Vec<String>,
) -> CargoResult<()> {
    let ws_def_feat = match ws_def_feat {
        Some(true) => "true",
        Some(false) => "false",
        None => "not specified",
    };
    if Edition::Edition2024 <= edition {
        anyhow::bail!("`default-features = false` cannot override workspace's `default-features`");
    } else {
        warnings.push(format!(
            "`default-features` is ignored for {label}, since `default-features` was \
                {ws_def_feat} for `workspace.dependencies.{label}`, \
                this could become a hard error in the future"
        ));
    }
    Ok(())
}

#[tracing::instrument(skip_all)]
pub fn to_real_manifest(
    contents: Option<String>,
    document: Option<toml::Spanned<toml::de::DeTable<'static>>>,
    original_toml: manifest::TomlManifest,
    normalized_toml: manifest::TomlManifest,
    features: Features,
    workspace_config: WorkspaceConfig,

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Set `default-features = false` at the workspace level: in `[workspace.dependencies] foo = { version = "1.0", default-features = false }`.
  2. If only one member needs it, do not inherit — declare the dependency directly in that member with `default-features = false`.
  3. Remove the member-level `default-features = false` and accept the workspace default.

Example fix

# before (member, edition 2024)
[dependencies]
foo = { workspace = true, default-features = false }
# after (set at workspace root)
# Cargo.toml (root):
[workspace.dependencies]
foo = { version = "1.0", default-features = false }
# member:
[dependencies]
foo = { workspace = true }
Defensive patterns

Strategy: validation

Validate before calling

// for edition >= 2024 members, forbid default-features on inherited deps
for (_k, item) in deps {
    if let Some(t) = item.as_table_like() {
        let inherits = t.get("workspace").and_then(|v| v.as_bool()) == Some(true);
        let overrides = t.contains_key("default-features");
        if edition >= 2024 && inherits && overrides {
            return Err("set default-features at the workspace level".into());
        }
    }
}

Prevention

When it happens

Trigger: A workspace member on edition 2024 with `foo = { workspace = true, default-features = false }` while `workspace.dependencies.foo` is defined (regardless of its own default-features setting).

Common situations: Upgrading a crate to edition 2024 that previously relied on the warning-only behavior; inheriting a dep but wanting fewer features.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/f9d0864994f9a68a.json. Report an issue: GitHub.