rust-lang/cargo · error

invalid package name `test`: it conflicts with Rust's…

Error message

invalid package name `test`: it conflicts with Rust's built-in test library{}

What it means

The literal name `test` is unconditionally rejected (hard error, not a warning) because it clashes with Rust's built-in `test` library that the test harness links against. This check is independent of `is_keyword` (note: `test` is not in the keyword list) and runs for every new package, bin or lib. The help again explains the `[[bin]]` workaround.

Solutions

  1. Choose a different name: `test-utils`, `my-tests`, `testing-ground`, etc.
  2. If you want a binary invoked as `test`, keep a valid package name and set `[[bin]] name = "test"` (though this can still confuse the test harness — prefer a distinct name).

Example fix

# before
$ cargo new test   # error: conflicts with Rust's built-in test library

# after
$ cargo new test-utils
Defensive patterns

Strategy: validation

Validate before calling

fn is_test_name(name: &str) -> bool { name == "test" }
// reject the literal name "test" for any new package.

Type guard

fn is_not_test_builtin(name: &str) -> bool { name != "test" }

Prevention

When it happens

Trigger: `cargo new test`, `cargo init --name test`, `cargo new --name test anything`.

Common situations: Creating a crate literally to experiment with testing and naming it `test`. Scaffolding from a directory named `test`. Tutorial repos that use `test` as a placeholder name.

Related errors


AI-assisted analysis of rust-lang/cargo@98a09e7e7d (2026-08-11). Data as JSON: /api/errors/ec7a4f32fa10892c. Report an issue: GitHub.

Appendix: source

Thrown at src/ops/cargo_new.rs:183

    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{}",
            bin_help()
        );
    }
    if ["core", "std", "alloc", "proc_macro", "proc-macro"].contains(&name) {
        shell.warn(format!(
            "package name `{}` may be confused with the package with that name in Rust's standard library\n\
            It is recommended to use a different name to avoid problems.{}",
            name,
            bin_help()
        ))?;
    }
    if restricted_names::is_windows_reserved(name) {
        if cfg!(windows) {
            anyhow::bail!(
                "invalid package name `{}`: it is a reserved Windows filename{}",
                name,

View on GitHub (pinned to 98a09e7e7d)