{"id":"8f5279bf27eac5dc","repo":"rust-lang/cargo","slug":"feature-feature-is-not-allowed-to-use-explicit","errorCode":null,"errorMessage":"feature `{feature}` is not allowed to use explicit `dep:` syntax","messagePattern":"feature `(.+?)` is not allowed to use explicit `dep:` syntax","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/bin/cargo/commands/add.rs","lineNumber":315,"sourceCode":"                                c.as_deref().expect(\"only none when there is 1\"),\n                                feature\n                            )\n                        })\n                        .collect::<Vec<_>>();\n                    anyhow::bail!(\n                        \"feature `{feature}` must be qualified by the dependency it's being activated for, like {}\",\n                        candidates.join(\", \")\n                    );\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)","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/bin/cargo/commands/add.rs#L297-L333","documentation":"From parse_dependencies (src/bin/cargo/commands/add.rs:314-316). Cargo's `add` command parses --features values via FeatureValue; the Dep { .. } variant corresponds to the explicit `dep:<name>` syntax (activate a dependency without its features). `cargo add` rejects this syntax entirely, because adding a dependency and simultaneously enabling a dep:-only reference is not meaningful in that flow.","triggerScenarios":"`cargo add serde --features dep:serde` or any `--features dep:<name>` token passed to `cargo add`.","commonSituations":"Copying a feature string from an existing Cargo.toml [features] table (where dep: is valid) into a `cargo add` command; misunderstanding that dep: is a manifest-level feature resolver construct, not an add flag.","solutions":["Drop the `dep:` prefix; just add the crate normally (`cargo add serde`).","If you need to enable a feature, use the plain feature name or dep/feature syntax.","Edit Cargo.toml [features] by hand if you genuinely need a dep: entry."],"exampleFix":"// before\ncargo add serde --features dep:serde\n\n// after\ncargo add serde","handlingStrategy":"validation","validationCode":"// Strip any explicit `dep:` tokens before passing to `cargo add`\nfn clean_add_features(features: &mut Vec<String>) {\n    features.retain(|f| !f.starts_with(\"dep:\"));\n}","typeGuard":"fn uses_dep_syntax(f: &str) -> bool {\n    f.starts_with(\"dep:\")\n}","tryCatchPattern":null,"preventionTips":["Remember `dep:` is a manifest [features] construct, not an add flag.","For `cargo add`, only use plain feature names or dep/feature syntax."],"tags":["cargo","add","features","cli"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}