rust-lang/cargo · error · anyhow::Error

found duplicate {target_kind} name {name}, but all {target_k

Error message

found duplicate {target_kind} name {name}, but all {target_kind} targets must have a unique name

What it means

Error "found duplicate {target_kind} name {name}, but all {target_kind} targets must have a unique name" thrown in rust-lang/cargo.

Source

Thrown at src/workspace/parser/targets.rs:894

}

fn inferred_to_toml_targets(inferred: &[(String, PathBuf)]) -> Vec<TomlTarget> {
    inferred
        .iter()
        .map(|(name, path)| TomlTarget {
            name: Some(name.clone()),
            path: Some(PathValue(path.clone())),
            ..TomlTarget::new()
        })
        .collect()
}

/// Will check a list of toml targets, and make sure the target names are unique within a vector.
fn validate_unique_names(targets: &[TomlTarget], target_kind: &str) -> CargoResult<()> {
    let mut seen = HashSet::default();
    for name in targets.iter().map(|e| name_or_panic(e)) {
        if !seen.insert(name) {
            anyhow::bail!(
                "found duplicate {target_kind} name {name}, \
                 but all {target_kind} targets must have a unique name",
                target_kind = target_kind,
                name = name
            );
        }
    }
    Ok(())
}

/// Will check a list of build scripts, and make sure script file stems are unique within a vector.
fn validate_unique_build_scripts(scripts: &[String]) -> CargoResult<()> {
    let mut seen = HashMap::default();
    for script in scripts {
        let stem = Path::new(script)
            .file_stem()
            .and_then(|s| s.to_str())
            .expect("previously normalized");

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Rename one of the duplicate targets so every target of that kind has a unique name.
  2. Remove the redundant target definition from Cargo.toml.

When it happens

Trigger: Thrown at src/workspace/parser/targets.rs:894 when the library encounters an invalid state.

Common situations: 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.


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/e6275e85b54a57f6.json. Report an issue: GitHub.