{"id":"4850b3821417a768","repo":"rust-lang/cargo","slug":"unrecognized-feature-for-crate","errorCode":null,"errorMessage":"unrecognized feature{} for crate {}: {}","messagePattern":"unrecognized feature(.+?) for crate (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ops/cargo_add/mod.rs","lineNumber":239,"sourceCode":"                                .map(|s| s.to_string())\n                                .coalesce(|x, y| if x.len() + y.len() < 78 {\n                                    Ok(format!(\"{x}, {y}\"))\n                                } else {\n                                    Err((x, y))\n                                })\n                                .into_iter()\n                                .format(\"\\n    \")\n                        )?;\n                    } else {\n                        writeln!(\n                            message,\n                            \"\\n\\n{} enabled features available\",\n                            activated.len()\n                        )?;\n                    }\n                }\n            }\n            anyhow::bail!(message.trim().to_owned());\n        }\n\n        print_dep_table_msg(&mut options.gctx.shell(), &dep)?;\n\n        manifest.insert_into_table(\n            &dep_table,\n            &dep,\n            workspace.gctx(),\n            workspace.root(),\n            options.spec.manifest().unstable_features(),\n        )?;\n        if dep.optional == Some(true) {\n            let is_namespaced_features_supported =\n                check_rust_version_for_optional_dependency(options.spec.rust_version())?;\n            if is_namespaced_features_supported {\n                let dep_key = dep.toml_key();\n                if !manifest.is_explicit_dep_activation(dep_key) {\n                    let table = manifest","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_add/mod.rs#L221-L257","documentation":"`cargo add` validates requested feature names against the set of features the chosen crate actually exposes (from its index summary or manifest). If any requested feature (including inherited ones) is not in `dep.available_features`, the operation is aborted. The message lists the unknown features and, when possible, appends edit-distance suggestions and the available enabled/disabled feature sets to help correct the typo.","triggerScenarios":"Running `cargo add serde --features derivee` (typo) or passing a feature that exists in a different version than the one selected, e.g. `cargo add tokio --features full` against a tokio version that lacks `full`. Both `dep.features` and `dep.inherited_features` are diffed against `available_features` at mod.rs:148-157.","commonSituations":"Feature renamed or removed between crate versions (e.g. a 0.x crate restructured its features), case mistakes (`--features Default`), hyphen/underscore confusion, or copying a feature list from outdated documentation.","solutions":["Re-read the error's printed feature list and pick the exact spelling it suggests (it includes edit-distance suggestions).","Check the selected crate version's feature list: `cargo add <crate> --dry-run` or consult `docs.rs/<crate>` for that version.","Pin to a version known to expose the feature (`cargo add <crate>@<version> --features <name>`) or drop the unknown feature."],"exampleFix":"# before\ncargo add serde --features derivee\n\n# after\ncargo add serde --features derive","handlingStrategy":"validation","validationCode":"// Fetch available features from the registry metadata and diff before invoking add.\n// Pseudocode using `crates_io_api` or `cargo metadata`:\nfn validate_features(crate_name: &str, version: &str, wanted: &[String]) -> Result<(), Vec<String>> {\n    let available: Vec<String> = fetch_features(crate_name, version); // your lookup\n    let unknown: Vec<_> = wanted.iter().filter(|f| !available.contains(f)).cloned().collect();\n    if unknown.is_empty() { Ok(()) } else { Err(unknown) }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Consult docs.rs for the exact version you pin before copying a feature list.","Normalize feature strings (lowercase, hyphen-vs-underscore) before passing them.","Prefer pinning the crate version (`name@ver`) so the feature set is deterministic."],"tags":["cargo-add","features","typo","version-mismatch"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}