{"id":"1f90f74cc1edb92e","repo":"rust-lang/cargo","slug":"invalid-package-name-it-is-a-reserved-window","errorCode":null,"errorMessage":"invalid package name `{}`: it is a reserved Windows filename{}","messagePattern":"invalid package name `(.+?)`: it is a reserved Windows filename(.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_new.rs","lineNumber":250,"sourceCode":"    }\n    if name == \"test\" {\n        anyhow::bail!(\n            \"invalid package name `test`: \\\n            it conflicts with Rust's built-in test library{}\",\n            bin_help()\n        );\n    }\n    if [\"core\", \"std\", \"alloc\", \"proc_macro\", \"proc-macro\"].contains(&name) {\n        shell.warn(format!(\n            \"package name `{}` may be confused with the package with that name in Rust's standard library\\n\\\n            It is recommended to use a different name to avoid problems.{}\",\n            name,\n            bin_help()\n        ))?;\n    }\n    if restricted_names::is_windows_reserved(name) {\n        if cfg!(windows) {\n            anyhow::bail!(\n                \"invalid package name `{}`: it is a reserved Windows filename{}\",\n                name,\n                name_help\n            );\n        } else {\n            shell.warn(format!(\n                \"package name `{}` is a reserved Windows filename\\n\\\n                This package will not work on Windows platforms.\",\n                name\n            ))?;\n        }\n    }\n    if restricted_names::is_non_ascii_name(name) {\n        shell.warn(format!(\n            \"invalid package name `{}`: contains non-ASCII characters\\n\\\n            Non-ASCII crate names are not supported by Rust.\",\n            name\n        ))?;","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_new.rs#L232-L268","documentation":"On Windows (cfg!(windows)), check_name hard-rejects a name that restricted_names::is_windows_reserved matches against reserved DOS device filenames (CON, PRN, NUL, COM1-9, LPT1-9, AUX, and case/extension variants). Creating a directory or files with such a name on Windows would fail or shadow a device, so Cargo refuses. On non-Windows the same condition only produces a warning.","triggerScenarios":"`cargo new CON`, `cargo new --name nul`, `cargo new COM1`, or running cargo new inside a folder whose name is a reserved device name, while actually on a Windows host.","commonSituations":"Cross-platform projects where a Linux developer created a crate named `aux` or `prn` that then breaks a Windows teammate; portmanteau names that happen to equal a device token; legacy short-name conventions.","solutions":["Rename to a non-reserved name (avoid CON, PRN, NUL, AUX, COM1-9, LPT1-9 in any case)","Pass `--name <safe-name>` to override","If you hit it on non-Windows only as a warning, treat it as a portability bug and rename anyway"],"exampleFix":"# before\ncargo new CON\n# after\ncargo new console   # or: cargo new CON --name console","handlingStrategy":"validation","validationCode":"fn is_windows_reserved(name: &str) -> bool {\n    let upper = name.to_uppercase();\n    let stem = upper.split('.').next().unwrap_or(\"\");\n    matches!(stem.as_bytes(),\n        b\"CON\" | b\"PRN\" | b\"AUX\" | b\"NUL\"\n    ) || (stem.starts_with(\"COM\") && (1..=9).contains(&stem[3..].parse::<u32>().unwrap_or(0)))\n      || (stem.starts_with(\"LPT\") && (1..=9).contains(&stem[3..].parse::<u32>().unwrap_or(0)))\n}\n\nif cfg!(windows) && is_windows_reserved(name) { /* reject */ }","typeGuard":"const WIN_RESERVED = /^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\\..*)?$/i;\nfunction isWindowsSafe(name: string): boolean { return !WIN_RESERVED.test(name); }","tryCatchPattern":null,"preventionTips":["Treat Windows reserved names as off-limits even on Unix for portability","Run a portability lint on crate and binary names in CI","When generating names from user input, reject DOS device tokens explicitly"],"tags":["cargo-new","package-name","windows","reserved-filename","portability"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}