{"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":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/workspace/dependency.rs","lineNumber":666,"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":648,"sourceCodeEnd":684,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/workspace/dependency.rs#L648-L684","documentation":"ArtifactKind::validate rejects a dependency artifact list that contains both `bin` (AllBinaries — selects every binary the crate provides) and any `bin:<name>` (SelectedBinary — a specific binary). Combining them is contradictory: `bin` already covers the named one, so specifying both is ambiguous and almost always a user mistake.","triggerScenarios":"Writing `artifact = [\"bin\", \"bin:mybin\"]` (or multiple entries mixing `bin` with one or more `bin:<name>`) in a single Cargo.toml dependency.","commonSituations":"Misunderstanding that `bin` means all binaries; copy-pasting artifact entries together; incrementally adding a named binary while leaving a blanket `bin`.","solutions":["Choose one strategy: use `bin` for all binaries, or list each with `bin:<name>`.","Remove the blanket `bin` entry when you list specific `bin:<name>` artifacts.","Re-read RFC 3452: `bin` and `bin:<name>` are mutually exclusive within one dependency."],"exampleFix":"# Cargo.toml before\n[dependencies.mycrate]\nartifact = [\"bin\", \"bin:mybin\"]\n\n# after (specific binaries only)\n[dependencies.mycrate]\nartifact = [\"bin:mybin\"]\n# or all binaries\n[dependencies.mycrate]\nartifact = [\"bin\"]","handlingStrategy":"validation","validationCode":"fn validate_artifact_list(kinds: &[String]) -> Result<(), String> {\n    let has_all = kinds.iter().any(|k| k == \"bin\");\n    let has_named = kinds.iter().any(|k| k.starts_with(\"bin:\") && k.len() > 4);\n    if has_all && has_named {\n        return Err(\"cannot mix 'bin' with 'bin:<name>'; choose one\".into());\n    }\n    Ok(())\n}","typeGuard":"fn artifact_list_is_consistent(kinds: &[String]) -> bool {\n    let all = kinds.iter().any(|k| k == \"bin\");\n    let named = kinds.iter().any(|k| k.starts_with(\"bin:\"));\n    !(all && named)\n}","tryCatchPattern":"match ArtifactKind::validate(parsed_kinds) {\n    Err(e) if e.to_string().contains(\"Cannot specify both 'bin' and 'bin:\") => {\n        eprintln!(\"pick either 'bin' (all) or specific 'bin:<name>' entries\");\n        return Err(e);\n    }\n    r => r,\n}","preventionTips":["Treat `bin` as exclusive: once used, do not add `bin:<name>` in the same dependency.","Lint the `artifact` array in CI toml checks.","Remove blanket `bin` when narrowing to specific binaries."],"tags":["manifest","artifact","dependency","validation","toml"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}