rust-lang/cargo · error
invalid package name
Error message
invalid package name `{}`: it conflicts with cargo's build directory names{} What it means
`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.
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).
Example fix
# before $ cargo new --bin build # error: conflicts with cargo's build directory names # after $ cargo new --bin build-tool
Defensive patterns
Strategy: validation
Validate before calling
const CONFLICTING: &[&str] = &["deps", "examples", "build", "incremental"];
fn is_conflicting_artifact_name(name: &str) -> bool { CONFLICTING.contains(&name) }
// reject for bin projects before `cargo new --bin <name>`. Type guard
fn safe_bin_package_name(name: &str) -> bool { !is_conflicting_artifact_name(name) } Prevention
- 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`).
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- {err}{help}
- invalid package name
- invalid package name `test`: it conflicts with Rust's…
- invalid package name
- can't specify both lib and binary outputs
AI-assisted analysis of rust-lang/cargo@98a09e7e7d (2026-08-11).
Data as JSON: /api/errors/5e0f46b20b3fa59f.
Report an issue: GitHub.
Appendix: source
Thrown at src/ops/cargo_new.rs:167
));
}
help
};
PackageName::new(name).map_err(|err| {
let help = bin_help();
anyhow::anyhow!("{err}{help}")
})?;
if restricted_names::is_keyword(name) {
anyhow::bail!(
"invalid package name `{}`: it is a Rust keyword{}",
name,
bin_help()
);
}
if restricted_names::is_conflicting_artifact_name(name) {
if has_bin {
anyhow::bail!(
"invalid package name `{}`: \
it conflicts with cargo's build directory names{}",
name,
name_help
);
} else {
shell.warn(format!(
"package `{}` will not support binary \
executables with that name, \
it conflicts with cargo's build directory names",
name
))?;
}
}
if name == "test" {
anyhow::bail!(
"invalid package name `test`: \
it conflicts with Rust's built-in test library{}",View on GitHub (pinned to 98a09e7e7d)