rust-lang/cargo · error
feature `{feature}` is not allowed to use explicit `dep:` sy
Error message
feature `{feature}` is not allowed to use explicit `dep:` syntax What it means
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.
Source
Thrown at src/bin/cargo/commands/add.rs:315
c.as_deref().expect("only none when there is 1"),
feature
)
})
.collect::<Vec<_>>();
anyhow::bail!(
"feature `{feature}` must be qualified by the dependency it's being activated for, like {}",
candidates.join(", ")
);
}
crates
.first_mut()
.expect("always at least one crate")
.1
.get_or_insert_with(IndexSet::default)
.insert(feature.to_owned());
}
FeatureValue::Dep { .. } => {
anyhow::bail!("feature `{feature}` is not allowed to use explicit `dep:` syntax",)
}
FeatureValue::DepFeature {
dep_name,
dep_feature,
..
} => {
if infer_crate_name {
anyhow::bail!(
"`{feature}` is unsupported when inferring the crate name, use `{dep_feature}`"
);
}
if dep_feature.contains('/') {
anyhow::bail!("multiple slashes in feature `{feature}` is not allowed");
}
crates.get_mut(&Some(dep_name.as_str().to_owned())).ok_or_else(|| {
anyhow::format_err!("feature `{dep_feature}` activated for crate `{dep_name}` but the crate wasn't specified")
})?
.get_or_insert_with(IndexSet::default)View on GitHub (pinned to 0e07a15537)
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.
Example fix
// before cargo add serde --features dep:serde // after cargo add serde
Defensive patterns
Strategy: validation
Validate before calling
// Strip any explicit `dep:` tokens before passing to `cargo add`
fn clean_add_features(features: &mut Vec<String>) {
features.retain(|f| !f.starts_with("dep:"));
} Type guard
fn uses_dep_syntax(f: &str) -> bool {
f.starts_with("dep:")
} Prevention
- Remember `dep:` is a manifest [features] construct, not an add flag.
- For `cargo add`, only use plain feature names or dep/feature syntax.
When it happens
Trigger: `cargo add serde --features dep:serde` or any `--features dep:<name>` token passed to `cargo add`.
Common situations: 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.
Related errors
- feature `{feature}` must be qualified by the dependency it's
- `{feature}` is unsupported when inferring the crate name, us
- multiple slashes in feature `{feature}` is not allowed
- invalid character `+` in dependency name: `+{toolchain}`
- cannot specify multiple crates with `--rename`
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/8f5279bf27eac5dc.json.
Report an issue: GitHub.