{"id":"5e0f46b20b3fa59f","repo":"rust-lang/cargo","slug":"invalid-package-name-it-conflicts-with-cargo","errorCode":null,"errorMessage":"invalid package name `{}`: it conflicts with cargo's build directory names{}","messagePattern":"invalid package name `(.+?)`: it conflicts with cargo's build directory names(.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_new.rs","lineNumber":218,"sourceCode":"            ));\n        }\n        help\n    };\n    PackageName::new(name).map_err(|err| {\n        let help = bin_help();\n        anyhow::anyhow!(\"{err}{help}\")\n    })?;\n\n    if restricted_names::is_keyword(name) {\n        anyhow::bail!(\n            \"invalid package name `{}`: it is a Rust keyword{}\",\n            name,\n            bin_help()\n        );\n    }\n    if restricted_names::is_conflicting_artifact_name(name) {\n        if has_bin {\n            anyhow::bail!(\n                \"invalid package name `{}`: \\\n                it conflicts with cargo's build directory names{}\",\n                name,\n                name_help\n            );\n        } else {\n            shell.warn(format!(\n                \"package `{}` will not support binary \\\n                executables with that name, \\\n                it conflicts with cargo's build directory names\",\n                name\n            ))?;\n        }\n    }\n    if name == \"test\" {\n        anyhow::bail!(\n            \"invalid package name `test`: \\\n            it conflicts with Rust's built-in test library{}\",","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_new.rs#L200-L236","documentation":"check_name reports this when restricted_names::is_conflicting_artifact_name(name) is true AND the package is a binary (has_bin). Names like `debug`, `release`, `build`, `deps`, `incremental` collide with the directory names Cargo writes under target/, so a binary crate with such a name would shadow its own build artifacts. For non-binary packages the same condition only emits a warning.","triggerScenarios":"`cargo new --bin debug`, `cargo new --bin build`, or a directory named `deps`/`incremental`/`examples` used for `cargo new --bin`. The bail at cargo_new.rs:217-223 fires because has_bin is true.","commonSituations":"Building a debugger or build-tool and naming the binary crate `debug` or `build`; cloning a tutorial folder whose name is one of the target/ subdirectories; CI scripts that create throwaway crates in a dir called `build`.","solutions":["Rename to something that does not collide with target/ subdirs (debug, release, build, deps, incremental, examples, ...)","Pass `--name <non-conflicting>` while keeping the directory name","If you only need a library (not a binary), drop --bin; the conflict then degrades to a warning"],"exampleFix":"# before\ncargo new --bin debug\n# after\ncargo new --bin my-debugger   # or: cargo new debug --name my-debugger","handlingStrategy":"validation","validationCode":"const CONFLICTING: &[&str] = &[\n    \"build\",\"checks\",\"deps\",\"examples\",\"incremental\",\"debug\",\"release\",\n];\nfn is_conflicting_artifact(name: &str) -> bool {\n    CONFLICTING.contains(&name)\n}\n\nif has_bin && is_conflicting_artifact(name) { /* reject */ }","typeGuard":"const CONFLICTING = new Set(['build','checks','deps','examples','incremental','debug','release']);\nfunction isSafeBinName(name: string): boolean { return !CONFLICTING.has(name); }","tryCatchPattern":null,"preventionTips":["Avoid target/ subdirectory names for binary crates","Run a pre-commit check on Cargo.toml [package].name against the conflicting list","Prefer descriptive names (my-debugger) over generic ones (debug)"],"tags":["cargo-new","package-name","build-artifacts","naming"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}