{"record":{"id":"482a2ea857c1875d","repo":"rust-lang/cargo","slug":"cannot-specify-both-bin-and-bin-name-binary","errorCode":null,"errorMessage":"Cannot specify both 'bin' and 'bin:<name>' binary artifacts, as 'bin' selects all available binaries.","messagePattern":"Cannot specify both 'bin' and 'bin:<name>' binary artifacts, as 'bin' selects all available binaries\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/workspace/dependency.rs","lineNumber":660,"sourceCode":"            \"staticlib\" => ArtifactKind::Staticlib,\n            _ => {\n                return kind\n                    .strip_prefix(\"bin:\")\n                    .map(|bin_name| ArtifactKind::SelectedBinary(bin_name.into()))\n                    .ok_or_else(|| {\n                        anyhow::anyhow!(\"'{}' is not a valid artifact specifier\", kind)\n                    });\n            }\n        })\n    }\n\n    fn validate(kinds: Vec<ArtifactKind>) -> CargoResult<Vec<ArtifactKind>> {\n        if kinds.iter().any(|k| matches!(k, ArtifactKind::AllBinaries))\n            && kinds\n                .iter()\n                .any(|k| matches!(k, ArtifactKind::SelectedBinary(_)))\n        {\n            anyhow::bail!(\n                \"Cannot specify both 'bin' and 'bin:<name>' binary artifacts, as 'bin' selects all available binaries.\"\n            );\n        }\n        let mut kinds_without_dupes = kinds.clone();\n        kinds_without_dupes.sort();\n        kinds_without_dupes.dedup();\n        let num_dupes = kinds.len() - kinds_without_dupes.len();\n        if num_dupes != 0 {\n            anyhow::bail!(\n                \"Found {} duplicate binary artifact{}\",\n                num_dupes,\n                (num_dupes > 1).then(|| \"s\").unwrap_or(\"\")\n            );\n        }\n        Ok(kinds)\n    }\n}\n","sourceCodeStart":642,"sourceCodeEnd":678,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/workspace/dependency.rs#L642-L678","documentation":"ArtifactKind::validate rejects combining the bare `bin` (all binaries) with one or more `bin:<name>` selections, because `bin` already implies every binary — listing specifics alongside it is ambiguous/redundant.","triggerScenarios":"Declaring a dependency artifact list mixing both forms: `artifact = [\"bin\", \"bin:mytool\"]`.","commonSituations":"Trying to be explicit while also selecting all binaries; merging two manifest snippets naively.","solutions":["Use only `bin` if you want all binaries.","Or list each specific `bin:<name>` you need, omitting the bare `bin`."],"exampleFix":"# before (Cargo.toml)\n# [dependencies]\n# foo = { version = \"1\", artifact = [\"bin\", \"bin:cli\"] }\n\n# after\n# [dependencies]\n# foo = { version = \"1\", artifact = \"bin\" }\n# or: foo = { version = \"1\", artifact = [\"bin:cli\"] }","handlingStrategy":"validation","validationCode":"fn validate_artifact_kinds(kinds: &[String]) -> Result<(), String> {\n    let has_all = kinds.iter().any(|k| k == \"bin\");\n    let has_specific = kinds.iter().any(|k| k.starts_with(\"bin:\"));\n    if has_all && has_specific {\n        return Err(\"cannot mix 'bin' with 'bin:<name>'\".into());\n    }\n    Ok(())\n}","typeGuard":"fn artifact_kinds_consistent(kinds: &[String]) -> bool {\n    let has_all = kinds.iter().any(|k| k == \"bin\");\n    let has_specific = kinds.iter().any(|k| k.starts_with(\"bin:\"));\n    !(has_all && has_specific)\n}","tryCatchPattern":null,"preventionTips":["Choose one selection strategy per dependency: all binaries (`bin`) OR specific binaries (`bin:<name>`).","Lint artifact lists in CI to catch mixed forms before they reach cargo."],"tags":["dependencies","artifacts","validation","manifest"],"backgroundTag":null,"analyzedSha":"98a09e7e7d62850f14e5b6132101fc1edd19a16f","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}