{"id":"88217d60505f9b01","repo":"rust-lang/cargo","slug":"only-none-when-there-is-1","errorCode":null,"errorMessage":"only none when there is 1","messagePattern":"only none when there is 1","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/bin/cargo/commands/add.rs","lineNumber":297,"sourceCode":"        }\n    }\n    for feature in matches\n        .get_many::<String>(\"features\")\n        .into_iter()\n        .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\",)","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/bin/cargo/commands/add.rs#L279-L315","documentation":"Internal invariant panic in `cargo add` feature parsing (src/bin/cargo/commands/add.rs:297). When `crates.len() > 1` (multiple crates being added) and cargo formats the disambiguation candidates `\"<crate>/<feature>\"`, it calls `.expect(\"only none when there is 1\")` on each crate key, asserting that a `None` key only exists in the single-crate (path/git) case. By construction the `crates` map either holds all-`Some(name)` keys (named crates) or a single `None` key (path/git with no names), so a `None` key with >1 entries should be impossible.","triggerScenarios":"Effectively unreachable through normal CLI use; would require `crates` to contain more than one entry with at least one `None` key — the construction logic at lines 253-280 prevents this. Triggerable only via an internal bug or memory corruption.","commonSituations":"Not user-reachable in practice; if observed it indicates a regression in `cargo add`'s argument handling. Report it as a cargo bug with the exact `cargo add` invocation.","solutions":["Report a bug to the cargo project with the full `cargo add ...` command and cargo version.","As a workaround, add crates one at a time rather than passing multiple names with --features."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Not user-reachable; guard at the CLI layer by ensuring you pass explicit crate names\n// when using --features with multiple crates.\nfn names_all_some(keys: &[Option<String>]) -> bool { keys.iter().all(|k| k.is_some()) }\n// when invoking cargo add with multiple crates, pass names explicitly so no None key appears","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass explicit crate names when using `cargo add <a> <b> --features ...`.","If a panic with this message appears, report it as a cargo bug."],"tags":["cargo","cargo-add","panic","invariant","internal"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}