rust-lang/cargo · error
multiple slashes in feature `{feature}` is not allowed
Error message
multiple slashes in feature `{feature}` is not allowed What it means
From parse_dependencies (src/bin/cargo/commands/add.rs:327-329). In the DepFeature branch it checks if dep_feature (the part after the slash) itself contains a `/`. Only one slash (dep/feature) is allowed; a second slash means a malformed nested feature spec, which Cargo rejects.
Source
Thrown at src/bin/cargo/commands/add.rs:328
.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)
.insert(dep_feature.as_str().to_owned());
}
}
}
let mut deps: Vec<DepOp> = Vec::new();
for (crate_spec, features) in crates {
let dep = DepOp {
crate_spec,
rename: rename.map(String::from),
features,
default_features,
optional,View on GitHub (pinned to 0e07a15537)
Solutions
- List each feature separately with its own dep/feature: `--features tokio/rt,tokio/macros`.
- Activate additional features of the dependency directly under that dependency in Cargo.toml.
- Verify there is exactly one `/` per feature token.
Example fix
// before cargo add tokio --features tokio/rt/macros // after cargo add tokio --features tokio/rt,tokio/macros
Defensive patterns
Strategy: validation
Validate before calling
// Reject feature tokens with more than one slash before invoking cargo add
fn valid_feature_token(f: &str) -> bool {
f.matches('/').count() <= 1
}
if !features.iter().all(|f| valid_feature_token(f)) {
eprintln!("each --features value may have at most one `/`");
} Type guard
fn has_at_most_one_slash(s: &str) -> bool {
s.matches('/').count() <= 1
} Prevention
- Use exactly one slash per feature: `dep/feature`.
- List multiple features as comma-separated tokens, not nested slashes.
When it happens
Trigger: `cargo add tokio --features tokio/rt/macros` or any --features token that, after the first split, still contains a slash.
Common situations: Trying to chain features across nested dependencies through one token; copying a path-like string into --features; misunderstanding that only `dep/feature` (one level) is supported.
Related errors
- feature `{feature}` must be qualified by the dependency it's
- feature `{feature}` is not allowed to use explicit `dep:` sy
- `{feature}` is unsupported when inferring the crate name, us
- 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/b6e45d01d091e580.json.
Report an issue: GitHub.