rust-lang/cargo · error

invalid package name

Error message

invalid package name `{}`: it is a reserved Windows filename{}

What it means

`is_windows_reserved` flags DOS-device names (`con`, `prn`, `aux`, `nul`, `com1`–`com9`, `lpt1`–`lpt9`). On Windows these cannot be filenames at all, so `cargo new`/`cargo init` on a Windows host (`cfg!(windows)`) hard-errors. On non-Windows hosts the same name is only a warning (the package would break if built on Windows). The check lowercases before matching, so case variants are caught too.

Solutions

  1. Rename to a non-reserved name: `aux-tool`, `com1-reader`, `prn-util`.
  2. If creating on non-Windows, heed the warning and rename before any Windows contributor clones.
  3. Avoid the reserved stems entirely as package or binary names.

Example fix

# before (on Windows)
$ cargo new con   # error: reserved Windows filename

# after
$ cargo new con-util
Defensive patterns

Strategy: validation

Validate before calling

const RESERVED: &[&str] = &["con","prn","aux","nul","com1","com2","com3","com4","com5","com6","com7","com8","com9","lpt1","lpt2","lpt3","lpt4","lpt5","lpt6","lpt7","lpt8","lpt9"];
fn is_windows_reserved(name: &str) -> bool { RESERVED.contains(&name.to_ascii_lowercase().as_str()) }

Type guard

fn is_windows_safe_name(name: &str) -> bool { !is_windows_reserved(name) }

Prevention

When it happens

Trigger: On Windows: `cargo new aux`, `cargo new --name COM1 x`, `cargo new Nul`. On Linux/macOS the same names produce a warning instead, but the resulting package is non-portable.

Common situations: Naming a serial-port tool (`com1`), a console utility (`con`), or a printer tool (`prn`). Cross-platform projects created on Linux with such a name that then fail on Windows teammates' machines.

Related errors


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

Appendix: source

Thrown at src/ops/cargo_new.rs:199

    }
    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,
                name_help
            );
        } else {
            shell.warn(format!(
                "package name `{}` is a reserved Windows filename\n\
                This package will not work on Windows platforms.",
                name
            ))?;
        }
    }
    if restricted_names::is_non_ascii_name(name) {
        shell.warn(format!(
            "invalid package name `{}`: contains non-ASCII characters\n\
            Non-ASCII crate names are not supported by Rust.",
            name
        ))?;

View on GitHub (pinned to 98a09e7e7d)