Why allow hyphens in crate names?

103 points nik-rev 46 comments

For me it's crate names. When I find a cool new crate foo_bar, I go to my Cargo.lock and write it there. (It's more convenient for me than cargo add).

And then my rust-analyzer fails to load the workspace - turns out the crate is actually called foo-bar so I must change it.

If hyphens turn into underscores in the code anyway, why even name the crate with hyphens, the extra step doesn't add any benefit.

I think I would do this:

  • When referring to a crate in Cargo.toml with underscores, they always translate into hyphens automatically (as a minimum)
  • When displaying names of crates, always use underscores even if in Cargo.toml it uses hyphens
  • in Edition 2027, disallow naming crates with hyphens