{"id":"c1fbced754aa17d3","repo":"rust-lang/cargo","slug":"feature-is-unsupported-when-inferring-the-crat","errorCode":null,"errorMessage":"`{feature}` is unsupported when inferring the crate name, use `{dep_feature}`","messagePattern":"`(.+?)` is unsupported when inferring the crate name, use `(.+?)`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/bin/cargo/commands/add.rs","lineNumber":323,"sourceCode":"                    );\n                }\n                crates\n                    .first_mut()\n                    .expect(\"always at least one crate\")\n                    .1\n                    .get_or_insert_with(IndexSet::default)\n                    .insert(feature.to_owned());\n            }\n            FeatureValue::Dep { .. } => {\n                anyhow::bail!(\"feature `{feature}` is not allowed to use explicit `dep:` syntax\",)\n            }\n            FeatureValue::DepFeature {\n                dep_name,\n                dep_feature,\n                ..\n            } => {\n                if infer_crate_name {\n                    anyhow::bail!(\n                        \"`{feature}` is unsupported when inferring the crate name, use `{dep_feature}`\"\n                    );\n                }\n                if dep_feature.contains('/') {\n                    anyhow::bail!(\"multiple slashes in feature `{feature}` is not allowed\");\n                }\n                crates.get_mut(&Some(dep_name.as_str().to_owned())).ok_or_else(|| {\n                    anyhow::format_err!(\"feature `{dep_feature}` activated for crate `{dep_name}` but the crate wasn't specified\")\n                })?\n                    .get_or_insert_with(IndexSet::default)\n                    .insert(dep_feature.as_str().to_owned());\n            }\n        }\n    }\n\n    let mut deps: Vec<DepOp> = Vec::new();\n    for (crate_spec, features) in crates {\n        let dep = DepOp {","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/bin/cargo/commands/add.rs#L305-L341","documentation":"From parse_dependencies (src/bin/cargo/commands/add.rs:317-326). When a crate name is being inferred (infer_crate_name is true, set when --path or --git is given with no explicit crate), the DepFeature variant (dep/feature syntax) is rejected because the dependency name is not yet known and cannot be matched against the crates IndexMap. Cargo tells you to use the bare feature name instead.","triggerScenarios":"`cargo add --git https://... --features serde/derive` where the crate name is inferred from the git source, so qualifying with `serde/derive` cannot be resolved.","commonSituations":"Adding from a path/git source and copying a feature spec from elsewhere that qualifies the dep name; the inferred crate name differs from what you assumed.","solutions":["Use the bare feature name: `--features derive`.","Pass the explicit crate name so it is not inferred, then `dep/feature` becomes valid: name the crate explicitly and use `--features <crate>/<feature>` only when not inferring (note: with an explicit name the code still expects the feature attached to that crate).","Edit Cargo.toml directly if you need precise control."],"exampleFix":"// before\ncargo add --git https://github.com/... --features mycrate/derive\n\n// after\ncargo add --git https://github.com/... --features derive","handlingStrategy":"validation","validationCode":"// When adding from --path/--git (inferred name), require bare feature names\nfn features_ok_for_infer(features: &[String], inferring: bool) -> bool {\n    if !inferring { return true; }\n    features.iter().all(|f| !f.contains('/'))\n}","typeGuard":"fn is_bare_feature(f: &str) -> bool {\n    !f.contains('/')\n}","tryCatchPattern":null,"preventionTips":["With --path/--git and no explicit crate name, use bare feature names only.","Pass an explicit crate name if you need dep/feature qualification."],"tags":["cargo","add","features","git","path","cli"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}