{"id":"fc70f227b05f60a0","repo":"rust-lang/cargo","slug":"the-binary-target-name-name-is-forbidden-it-c","errorCode":null,"errorMessage":"the binary target name `{name}` is forbidden, it conflicts with cargo's build directory names","messagePattern":"the binary target name `(.+?)` is forbidden, it conflicts with cargo's build directory names","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/workspace/parser/targets.rs","lineNumber":1162,"sourceCode":"        .as_deref()\n        .unwrap_or_else(|| panic!(\"target name is required\"))\n}\n\nfn validate_lib_name(target: &TomlTarget, warnings: &mut Vec<String>) -> CargoResult<()> {\n    validate_target_name(target, TARGET_KIND_HUMAN_LIB, TARGET_KIND_LIB, warnings)?;\n    let name = name_or_panic(target);\n    if name.contains('-') {\n        anyhow::bail!(\"library target names cannot contain hyphens: {}\", name)\n    }\n\n    Ok(())\n}\n\nfn validate_bin_name(bin: &TomlTarget, warnings: &mut Vec<String>) -> CargoResult<()> {\n    validate_target_name(bin, TARGET_KIND_HUMAN_BIN, TARGET_KIND_BIN, warnings)?;\n    let name = name_or_panic(bin).to_owned();\n    if restricted_names::is_conflicting_artifact_name(&name) {\n        anyhow::bail!(\n            \"the binary target name `{name}` is forbidden, \\\n                 it conflicts with cargo's build directory names\",\n        )\n    }\n\n    Ok(())\n}\n\nfn validate_target_name(\n    target: &TomlTarget,\n    target_kind_human: &str,\n    target_kind: &str,\n    warnings: &mut Vec<String>,\n) -> CargoResult<()> {\n    match target.name {\n        Some(ref name) => {\n            if name.trim().is_empty() {\n                anyhow::bail!(\"{} target names cannot be empty\", target_kind_human)","sourceCodeStart":1144,"sourceCodeEnd":1180,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/workspace/parser/targets.rs#L1144-L1180","documentation":"Error \"the binary target name `{name}` is forbidden, it conflicts with cargo's build directory names\" thrown in rust-lang/cargo.","triggerScenarios":"Thrown at src/workspace/parser/targets.rs:1162 when the library encounters an invalid state.","commonSituations":"Occurs when a `[[bin]]` name collides with Cargo's reserved build directory names (e.g. `build`, `check`, `deps`, `examples`, `incremental`). Pick a different binary name.","solutions":["Rename the binary target to a name that does not conflict with Cargo's build directory names (e.g. avoid `build`, `deps`, `examples`, `incremental`)."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}