Skip to content

cargo init claims you can make a binary called "udpinject.rs" by configuring "udpinject-rs" ex post. This is forbidden actually. #16396

@nabijaczleweli

Description

@nabijaczleweli

Problem

$ cargo init udpinject.rs
    Creating binary (application) package
error: invalid character `.` in package name: `udpinject.rs`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters)
If you need a package name to not match the directory name, consider using --name flag.
If you need a binary with the name "udpinject.rs", use a valid package name, and set the binary name to be different from the package. This can be done by setting the binary filename to `src/bin/udpinject.rs.rs` or change the name in Cargo.toml with:

    [[bin]]
    name = "udpinject.rs"
    path = "src/main.rs"

$ cargo init udpinject-rs
    Creating binary (application) package
$ cd udpinject-rs/
udpinject-rs$ subl Cargo.toml
udpinject-rs$ cat Cargo.toml
[package]
name = "udpinject-rs"
version = "0.1.0"
edition = "2024"

[[bin]]
name = "udpinject.rs"
path = "src/main.rs"

[dependencies]
udpinject-rs$ cargo build
   Compiling udpinject-rs v0.1.0 (/home/nabijaczleweli/uwu/udpinject-rs)
error: invalid character '.' in crate name: `udpinject.rs`
  |
  = help: you can either pass `--crate-name` on the command line or add `#![crate_name = "…"]` to set the crate name

error: could not compile `udpinject-rs` (bin "udpinject.rs") due to 1 previous error
udpinject-rs$ subl src/main.rs
udpinject-rs$ head -n1 src/main.rs
#![crate_name="udpinject.rs"]
udpinject-rs$ cargo build
   Compiling udpinject-rs v0.1.0 (/home/nabijaczleweli/uwu/udpinject-rs)
error: invalid character '.' in crate name: `udpinject.rs`
  |
  = help: you can either pass `--crate-name` on the command line or add `#![crate_name = "…"]` to set the crate name

error: could not compile `udpinject-rs` (bin "udpinject.rs") due to 1 previous error

Possible Solution(s)

Either allow this, like, normally-named binary; or don't claim it's allowed.

Version

cargo 1.88.0 (873a06493 2025-05-10)
release: 1.88.0
commit-hash: 873a0649350c486caf67be772828a4f36bb4734c
commit-date: 2025-05-10
host: x86_64-unknown-linux-gnu
libgit2: 1.9.0 (sys:0.20.0 vendored)
libcurl: 8.12.1-DEV (sys:0.4.80+curl-8.12.1 vendored ssl:OpenSSL/3.4.1)
ssl: OpenSSL 3.4.1 11 Feb 2025
os: Debian 12.0.0 (bookworm) [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugCommand-initS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions