Older version:
Currently, there is a sort of equivalence relation within crate names. A crate is equal to another crate if its name is equal, except for the characters - and _, where either can be used interchangeably. Only one crate can be on crates.io using this equivalence relation, but when used it must be spelled exactly, with the correct usage of - and _. I propose to
- Accept either spellings in
Cargo.toml, so a crate named proc-macro2 can be used like[dependencies]
proc_macro2 = "0.4"
and cargo will use proc-macro2. Currently this errors, with a “did you mean” message.
- (More controversial) Make crates in the same equivalence class completely equivalent. Allow a cargo crate called
my-crate_with-both to be published where the local name is anything equivalent to this (for example my_crate_with-both). Choose a canonical form to display on crates.io (I propose all _ so it matches what you write in code).
- (Still more controversial) Emit a warning when
- is used, encouraging everyone to move to the canonical representation.
I couldn’t find any prior RFC for this, although it’s such an obvious idea that it may have been presented already. In that case I apologize for duplicating.
I’m interested to see what other people think about this. It seems odd to me that a_crate and a-crate are equivalent in the exclusion sense (only one of them can be on crates.io), but not in any other sense, but there may be reasons for the way things are currently. I’d like to hear them!
Arguments for
- Simpler for new users - everything uses the same pattern. It’s confusing when you always write
crate_name in code, but sometimes (but not always) crate-name in Cargo.toml.
- No paper-cut when you use the wrong form (you used
proc_macro2 when it’s proc-macro2).
Arguments against
- It’s more effort than doing nothing.
- Maybe having the two forms is equally/more confusing than the current situation.
- The warnings might be annoying because you prefer using the
crate-name form, and you’d have to change the name everywhere to get rid of the warnings.
Questions
What happens when you’re not using cargo? Should rustc except --extern with either form?
EDIT typos, arguments and questions