Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize crate names when reading Cargo.toml #4383

Closed
spinda opened this issue Aug 8, 2017 · 3 comments
Closed

Normalize crate names when reading Cargo.toml #4383

spinda opened this issue Aug 8, 2017 · 3 comments
Labels
A-crate-dependencies Area: [dependencies] of any kind A-interacts-with-crates.io Area: interaction with registries C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@spinda
Copy link

spinda commented Aug 8, 2017

This seeks to address two problems.

- vs _

The Rust community tends to use - and _ as word separators in package/crate names. However, the allowance of both characters, and the fact that - is invalid in a crate name in Rust source, has created something of a messy situation. For some crates, users need to write - in their Cargo.toml and _ in their Rust source (tokio-core, rustc-serialize, num-traits). For others, _ is used in both places (lazy_static, serde_derive, symbolic_expressions). This creates a point of confusion and imposes additional cognitive overhead.

Proposal: teach Cargo to treat these characters as equivalent when reading crate names from Cargo.toml, normalizing them to _ (matching their representation in Rust source).

According to @Manishearth:

  • Crates.io considers them to be the same when uploading crates
  • Rustc will always see crate names with hyphens converted to underscores

(So there are no clashing crate names)

cAsE senSITIvIty

What was that one package called? inflector? Oh, no, it's Inflector. But crates.io will recognize any of inflector, Inflector, or even inFLeCtOr. And in Rust source, you're expected to write extern crate inflector.

Proposal: internally lowercase crate names read from Cargo.toml and treat case variations as equivalent. Since Rust only allows ASCII crate names, there's no need to deal with any of the oddities of Unicode case normalization.

@matklad
Copy link
Member

matklad commented Aug 9, 2017

Yeah, we've been historically lax about - vs _:

if let Some(ref name) = lib.name {
// XXX: other code paths dodge this validation
if name.contains('-') {
bail!("library target names cannot contain hyphens: {}", name)

@alexcrichton
Copy link
Member

Seems like a great idea to me! The actual implementation here though requires crates.io, the index, and Cargo to all agree on a canonicalization of a name. The index right now is keyed off the actual crate's name (e.g. what was uploaded to crates.io). This means there's no efficient mechanism of performing normalization right now in Cargo, and the format of the index would need to change to support this.

I also think that we shouldn't normalize case because rustc itself doesn't do that, just normalize - and _ which rustc does indeed do. For example extern crate Foo and extern crate foo I believe are considered unique items in the compiler. Cargo, however, for other technical reasons will likely continue to forbid two crates like Foo and foo existing.

@carols10cents carols10cents added A-crate-dependencies Area: [dependencies] of any kind A-interacts-with-crates.io Area: interaction with registries C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` labels Aug 27, 2017
@carols10cents
Copy link
Member

Closing as a duplicate of #2775.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-crate-dependencies Area: [dependencies] of any kind A-interacts-with-crates.io Area: interaction with registries C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

4 participants