rust-lang/cargo · error

feature `{feature}` must be qualified by the dependency it's

Error message

feature `{feature}` must be qualified by the dependency it's being activated for, like {}

What it means

From parse_dependencies (src/bin/cargo/commands/add.rs:290-306). When `cargo add` is given more than one crate in a single invocation and a --features value is an unqualified feature name (FeatureValue::Feature), Cargo cannot tell which crate it belongs to, so it bails and lists the candidate `crate/feature` qualifications you should use instead.

Source

Thrown at src/bin/cargo/commands/add.rs:302

        .flatten()
        .map(String::as_str)
        .flat_map(parse_feature)
    {
        let parsed_value = FeatureValue::new(feature.into());
        match parsed_value {
            FeatureValue::Feature(_) => {
                if 1 < crates.len() {
                    let candidates = crates
                        .keys()
                        .map(|c| {
                            format!(
                                "`{}/{}`",
                                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,
                ..

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Qualify the feature with its crate: `--features tokio/rt` (dep/feature syntax).
  2. Add the crates in separate `cargo add` invocations so the feature is unambiguous.
  3. Edit Cargo.toml [features] manually if you need to map one feature across multiple deps.

Example fix

// before
cargo add serde tokio --features rt

// after
cargo add serde tokio --features tokio/rt
Defensive patterns

Strategy: validation

Validate before calling

// When adding >1 crate, ensure every --features value is qualified (dep/feature)
fn features_ok(crates: &[String], features: &[String]) -> bool {
    if crates.len() <= 1 { return true; }
    features.iter().all(|f| f.contains('/') || f == "default")
}

Type guard

fn is_qualified_feature(f: &str) -> bool {
    // valid forms: dep/feature (exactly one slash), or 'default'
    f == "default" || f.matches('/').count() == 1
}

Prevention

When it happens

Trigger: `cargo add serde tokio --features rt` — `rt` is ambiguous across two newly added crates, so you must write `tokio/rt`.

Common situations: Adding several crates at once and trying to enable a feature common in name across them; batching dependency additions in a script.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/67384042ef547d42.json. Report an issue: GitHub.