{"record":{"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":null,"httpStatus":null,"severity":"error","filePath":"src/ops/cargo_new.rs","lineNumber":167,"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":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/ops/cargo_new.rs#L149-L185","documentation":"`restricted_names::is_conflicting_artifact_name` flags exactly `deps`, `examples`, `build`, and `incremental` — these are subdirectory names cargo creates under `target/`. When the package has a binary target (`has_bin`), naming the package one of these would collide with cargo's own output layout, so it is a hard error. For lib-only packages it downgrades to a warning.","triggerScenarios":"`cargo new --bin build`, `cargo new --bin deps`, `cargo new --bin examples`, or `cargo new --bin incremental`. The `(has_bin == true)` branch is what bails.","commonSituations":"Naming a CLI tool after its function (`build`, `examples` runner). Copying a folder named `examples` into a new bin project. Auto-naming from a directory that happens to be one of these four.","solutions":["Rename the package to something non-conflicting, e.g. `build-tool`, `deps-cli`, `example-runner`.","If you only need a library (no binary), the name is allowed with just a warning — but a binary by that exact name is still impossible.","Keep a valid package name and rename the binary via `[[bin]] name = \"build\"` only if you accept the target-path consequences (still discouraged)."],"exampleFix":"# before\n$ cargo new --bin build   # error: conflicts with cargo's build directory names\n\n# after\n$ cargo new --bin build-tool","handlingStrategy":"validation","validationCode":"const CONFLICTING: &[&str] = &[\"deps\", \"examples\", \"build\", \"incremental\"];\nfn is_conflicting_artifact_name(name: &str) -> bool { CONFLICTING.contains(&name) }\n// reject for bin projects before `cargo new --bin <name>`.","typeGuard":"fn safe_bin_package_name(name: &str) -> bool { !is_conflicting_artifact_name(name) }","tryCatchPattern":null,"preventionTips":["Avoid the four cargo output-dir names (`deps`, `examples`, `build`, `incremental`) for any binary package.","For libraries these are only warnings, but prefer distinct names for portability.","Suffix utility names that conceptually match these words (e.g. `build-tool`)."],"tags":["package-name","cargo-new","build-artifacts","naming"],"backgroundTag":null,"analyzedSha":"98a09e7e7d62850f14e5b6132101fc1edd19a16f","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}