{"id":"e6275e85b54a57f6","repo":"rust-lang/cargo","slug":"found-duplicate-target-kind-name-name-but-all","errorCode":null,"errorMessage":"found duplicate {target_kind} name {name}, but all {target_kind} targets must have a unique name","messagePattern":"found duplicate (.+?) name (.+?), but all (.+?) targets must have a unique name","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/workspace/parser/targets.rs","lineNumber":894,"sourceCode":"}\n\nfn inferred_to_toml_targets(inferred: &[(String, PathBuf)]) -> Vec<TomlTarget> {\n    inferred\n        .iter()\n        .map(|(name, path)| TomlTarget {\n            name: Some(name.clone()),\n            path: Some(PathValue(path.clone())),\n            ..TomlTarget::new()\n        })\n        .collect()\n}\n\n/// Will check a list of toml targets, and make sure the target names are unique within a vector.\nfn validate_unique_names(targets: &[TomlTarget], target_kind: &str) -> CargoResult<()> {\n    let mut seen = HashSet::default();\n    for name in targets.iter().map(|e| name_or_panic(e)) {\n        if !seen.insert(name) {\n            anyhow::bail!(\n                \"found duplicate {target_kind} name {name}, \\\n                 but all {target_kind} targets must have a unique name\",\n                target_kind = target_kind,\n                name = name\n            );\n        }\n    }\n    Ok(())\n}\n\n/// Will check a list of build scripts, and make sure script file stems are unique within a vector.\nfn validate_unique_build_scripts(scripts: &[String]) -> CargoResult<()> {\n    let mut seen = HashMap::default();\n    for script in scripts {\n        let stem = Path::new(script)\n            .file_stem()\n            .and_then(|s| s.to_str())\n            .expect(\"previously normalized\");","sourceCodeStart":876,"sourceCodeEnd":912,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/workspace/parser/targets.rs#L876-L912","documentation":"Error \"found duplicate {target_kind} name {name}, but all {target_kind} targets must have a unique name\" thrown in rust-lang/cargo.","triggerScenarios":"Thrown at src/workspace/parser/targets.rs:894 when the library encounters an invalid state.","commonSituations":"Occurs when two targets of the same kind (e.g. two `[[bin]]` entries) share a name. Rename one target so every target of a given kind has a unique name.","solutions":["Rename one of the duplicate targets so every target of that kind has a unique name.","Remove the redundant target definition from Cargo.toml."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}