{"record":{"id":"4850b3821417a768","repo":"rust-lang/cargo","slug":"unrecognized-feature-for-crate","errorCode":null,"errorMessage":"unrecognized feature{} for crate {}: {}","messagePattern":"unrecognized feature(.+?) for crate (.+?): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_add/mod.rs","lineNumber":241,"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":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/ops/cargo_add/mod.rs#L223-L259","documentation":"Thrown by cargo add when the user requests features via --features or -F that do not exist on the target crate. The error message lists the unrecognized feature names, suggests close matches via edit-distance, and shows available features. The bail occurs at line 240 after the full message is assembled.","triggerScenarios":"Running `cargo add foo --features bar` where 'bar' is not a feature defined in crate 'foo'. The unknown_features set is computed by diffing requested features against dep.available_features.","commonSituations":"Typo in a feature name. The feature was renamed or removed in a newer version of the crate. Confusing features from a different crate. Using crate-level features that are only available as dependency features.","solutions":["Check the error message for suggested features via edit-distance matching","Review the 'available features' list printed in the error output","Inspect the crate's Cargo.toml or documentation to find valid feature names","Update the feature name to match an existing one"],"exampleFix":"# before\ncargo add serde --features derrive\n# error: unrecognized feature `derrive` for crate serde\n\n# after — fix typo\ncargo add serde --features derive","handlingStrategy":"validation","validationCode":"// Validate feature names before running cargo add\nfn validate_features(crate_name: &str, requested: &[String]) -> Result<(), String> {\n    // Fetch available features from the crate's metadata\n    let output = std::process::Command::new(\"cargo\")\n        .args([\"info\", crate_name, \"--format-version\", \"1\"])\n        .output().map_err(|e| e.to_string())?;\n    let metadata: serde_json::Value = serde_json::from_slice(&output.stdout)\n        .map_err(|e| e.to_string())?;\n    let available: Vec<&str> = metadata[\"features\"].as_object()\n        .map(|m| m.keys().map(|s| s.as_str()).collect())\n        .unwrap_or_default();\n    for feat in requested {\n        if !available.contains(&feat.as_str()) {\n            return Err(format!(\"unrecognized feature `{feat}` for crate {crate_name}\"));\n        }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check available features via cargo info <crate> or the crate's documentation before specifying --features","Watch for edit-distance suggestions in the error output for typo correction","Be aware that features may change between major versions of a crate"],"tags":["cargo-add","features","dependency"],"backgroundTag":null,"analyzedSha":"98a09e7e7d62850f14e5b6132101fc1edd19a16f","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}