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

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

Error message

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

What it means

check_name hard-rejects the exact name `test` because it collides with Rust's built-in test harness crate (extern crate test), which is implicitly available to every Rust program. The trailing {help} suggests a [[bin]] override. Unlike the broader std-library names (core/std/alloc) which only warn, `test` is always fatal.

Source

Thrown at src/ops/cargo_new.rs:234

    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 0e07a15537)

Solutions

  1. Choose a different name such as `tester`, `test-utils`, or `my-tests`
  2. Use `--name <something-else>` to override the directory-derived name
  3. Rename the parent directory from `test` to e.g. `tests` or `test-harness`

Example fix

# before
cargo new test
# after
cargo new test --name my-test   # or move dir: cargo new my-test
Defensive patterns

Strategy: validation

Validate before calling

fn is_reserved_std_name(name: &str) -> bool {
    matches!(name, "test")
}

if is_reserved_std_name(name) { /* reject; 'test' is always invalid */ }

Type guard

function isNotTestName(name: string): boolean { return name !== 'test'; }

Prevention

When it happens

Trigger: `cargo new test`, `cargo new --name test`, or running `cargo new` inside a directory literally named `test`. The name == "test" comparison at cargo_new.rs:233 fires.

Common situations: Creating a crate inside a folder called `test/` (common monorepo layout), scaffolding a crate whose purpose is testing, or following a tutorial that uses `test` as the example name.

Related errors


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