{"id":"67384042ef547d42","repo":"rust-lang/cargo","slug":"feature-feature-must-be-qualified-by-the-depen","errorCode":null,"errorMessage":"feature `{feature}` must be qualified by the dependency it's being activated for, like {}","messagePattern":"feature `(.+?)` must be qualified by the dependency it's being activated for, like (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/bin/cargo/commands/add.rs","lineNumber":302,"sourceCode":"        .flatten()\n        .map(String::as_str)\n        .flat_map(parse_feature)\n    {\n        let parsed_value = FeatureValue::new(feature.into());\n        match parsed_value {\n            FeatureValue::Feature(_) => {\n                if 1 < crates.len() {\n                    let candidates = crates\n                        .keys()\n                        .map(|c| {\n                            format!(\n                                \"`{}/{}`\",\n                                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                ..","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/bin/cargo/commands/add.rs#L284-L320","documentation":"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.","triggerScenarios":"`cargo add serde tokio --features rt` — `rt` is ambiguous across two newly added crates, so you must write `tokio/rt`.","commonSituations":"Adding several crates at once and trying to enable a feature common in name across them; batching dependency additions in a script.","solutions":["Qualify the feature with its crate: `--features tokio/rt` (dep/feature syntax).","Add the crates in separate `cargo add` invocations so the feature is unambiguous.","Edit Cargo.toml [features] manually if you need to map one feature across multiple deps."],"exampleFix":"// before\ncargo add serde tokio --features rt\n\n// after\ncargo add serde tokio --features tokio/rt","handlingStrategy":"validation","validationCode":"// When adding >1 crate, ensure every --features value is qualified (dep/feature)\nfn features_ok(crates: &[String], features: &[String]) -> bool {\n    if crates.len() <= 1 { return true; }\n    features.iter().all(|f| f.contains('/') || f == \"default\")\n}","typeGuard":"fn is_qualified_feature(f: &str) -> bool {\n    // valid forms: dep/feature (exactly one slash), or 'default'\n    f == \"default\" || f.matches('/').count() == 1\n}","tryCatchPattern":null,"preventionTips":["When batching `cargo add a b ...`, always qualify features as `dep/feature`.","Or add crates one per invocation to keep features unambiguous."],"tags":["cargo","add","features","cli"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}