rust-lang/cargo · error

Use of `default_features` in

Error message

Use of `default_features` in `{key}` is unsupported, please switch to `default-features`

What it means

Thrown by the manifest editor dependency parser when a dependency table contains the key 'default_features' (with an underscore). Cargo's canonical field name is 'default-features' (with a hyphen); the underscore variant is not accepted by the editor. The message directs the user to rename the key. Note this is a hard rejection (bail), not a warning, because the editor cannot safely guess intent.

Solutions

  1. Rename the key from 'default_features' to 'default-features' in the dependency table.
  2. If a code generator produced the underscore form, fix its output template to use the hyphenated key.
  3. Run `cargo fix --edition` or a manifest linter to normalize the field name.

Example fix

# before
[dependencies]
serde = { version = "1.0", default_features = false }

# after
[dependencies]
serde = { version = "1.0", default-features = false }
Defensive patterns

Strategy: validation

Validate before calling

fn check_no_underscore_default_features(table: &toml_edit::Item) -> Result<(), String> {
    if let Some(t) = table.as_table_like() {
        if t.contains_key("default_features") {
            return Err("rename `default_features` to `default-features`".into());
        }
    }
    Ok(())
}

Type guard

fn uses_hyphen_default_features(table: &dyn toml_edit::TableLike) -> bool {
    !table.contains_key("default_features")
}

Prevention

When it happens

Trigger: Calling Dependency::from_toml on a table containing the key 'default_features'. This frequently comes from JSON-serialized manifests (JSON has no hyphens in conventional identifiers) or from copy-paste of Python/JS-style config.

Common situations: A developer writes default_features = false by habit from other ecosystems. A tool that round-trips Cargo.toml through JSON and back converts hyphens to underscores. Copying dependency snippets from blog posts that use the underscore form.

Related errors


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

Appendix: source

Thrown at src/workspace/editor/dependency.rs:342

                        "dependency ({key}) specified without \
                        providing a local path, Git repository, version, or \
                        workspace dependency to use"
                    );
                };
            let registry = if let Some(value) = table.get("registry") {
                Some(
                    value
                        .as_str()
                        .ok_or_else(|| invalid_type(key, "registry", value.type_name(), "string"))?
                        .to_owned(),
                )
            } else {
                None
            };

            let default_features = table.get("default-features").and_then(|v| v.as_bool());
            if table.contains_key("default_features") {
                anyhow::bail!(
                    "Use of `default_features` in `{key}` is unsupported, please switch to `default-features`"
                );
            }

            let features = if let Some(value) = table.get("features") {
                Some(
                    value
                        .as_array()
                        .ok_or_else(|| invalid_type(key, "features", value.type_name(), "array"))?
                        .iter()
                        .map(|v| {
                            v.as_str().map(|s| s.to_owned()).ok_or_else(|| {
                                invalid_type(key, "features", v.type_name(), "string")
                            })
                        })
                        .collect::<CargoResult<IndexSet<String>>>()?,
                )
            } else {

View on GitHub (pinned to eb98b54bc9)