Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAccept hyphen in crate name in place of underscore #2775
Comments
dtolnay
referenced this issue
Jun 6, 2016
Closed
Show crate names with hyphens in place of underscores #350
This comment has been minimized.
This comment has been minimized.
|
Cargo is somewhat agnostic between I'd personally prefer to not accept both |
This comment has been minimized.
This comment has been minimized.
|
Makes sense, and I don't have a strong preference myself. I saw this comment from @steveklabnik and figured this would be a step toward tooling that reflects the conventions we would like developers to use. Is there a rationale for crates.io vs cargo behaving differently from each other?
Fair, but I would rather see |
This comment has been minimized.
This comment has been minimized.
|
I don't really know why crates.io is agnostic, it wasn't originally and I think that was a patch added after the fact, would have to track that down. Yeah it's easier to not have to remember, but to me it's more of a downside as it's disguising what's actually happening under the hood. |
dtolnay
closed this
Jun 8, 2016
This comment has been minimized.
This comment has been minimized.
|
The crates.io change was rust-lang/crates.io@89bc5dd. |
This comment has been minimized.
This comment has been minimized.
The current behavior of crates.io is defined by RFC 940:
|
This comment has been minimized.
This comment has been minimized.
|
I'd like to re-open this issue, I think this is a bug and we should fix it. (Maybe we can talk about it in a cargo meeting).
At first glance, this makes sense, but I think it doesn't hold as much water when you consider:
In contrast, users who accidentally add |
dtolnay
reopened this
Sep 6, 2017
This comment has been minimized.
This comment has been minimized.
|
Reopened. I have also come to feel much more strongly about this in the past year. |
This comment has been minimized.
This comment has been minimized.
|
I also agree this is worthwhile to fix. Implementation-wise this won't be easy though, I think, as it'll require changes to the crate index. The changes in Cargo itself after that, though, are likely nominal. |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton That would be a problem, why isn't it sufficient to change how we match the dependency name against the index file to be neutral to underscores (e.g. retry if there's no file with the characters swapped)? (It'd be better if the index were normalized, but that seems quite challenging). |
This comment has been minimized.
This comment has been minimized.
|
Right now we don't load the entire index in-memory and we currently also don't try to browse the entire index, rather given a crate we drill into exactly which file it's supposed to be. If we have |
This comment has been minimized.
This comment has been minimized.
|
Makes sense, so I think what we should do:
Is a divergence between the name in the lock and the toml going to be a problem? EDIT: Also I'd like to write the PR for this to get more acquainted with cargo's codebase :) |
This comment has been minimized.
This comment has been minimized.
|
Yeah that sounds like it could work! I think we'll have to maek sure that a |
carols10cents
added
A-crate-dependencies
A-interacts-with-crates.io
C-feature-request
labels
Sep 25, 2017
carols10cents
referenced this issue
Sep 25, 2017
Closed
Normalize crate names when reading Cargo.toml #4383
carols10cents
referenced this issue
Jul 3, 2018
Open
Support depending on crates with any case of the original name #5678
This comment has been minimized.
This comment has been minimized.
Is there a better way of doing this then brute force? With out changing the index in ways that brack older cargos / exiting projects? |
This comment has been minimized.
This comment has been minimized.
|
Brute force take an exponential |
Eh2406
referenced this issue
Jul 6, 2018
Merged
Make index lookup robust to _ vs -, but don't let the user get it wrong. #5691
bors
added a commit
that referenced
this issue
Jul 16, 2018
This comment has been minimized.
This comment has been minimized.
dhardy
commented
Aug 4, 2018
|
Why not go further and normalise all names to use hyphens |
This comment has been minimized.
This comment has been minimized.
|
Because the index wuld need to have both names so that pre-normalise cargo and post-normalise cargo can find it, and that makes for 2 sources of truth. |
This comment has been minimized.
This comment has been minimized.
dhardy
commented
Aug 13, 2018
|
No it wouldn't if deployed via a new version of Cargo. Unfortunately this would not be backwards compatible (i.e. old versions of Cargo would require correct |
This comment has been minimized.
This comment has been minimized.
mqudsi
commented
Sep 29, 2018
|
A much nicer solution would have been to restrict crate names to a whitelist of characters that contains only one of those two symbols from day 1. Alas, time travel is not really an option. |
This comment has been minimized.
This comment has been minimized.
danielwaterworth
commented
Oct 19, 2018
|
One thing that could be done to lessen the problem over time would be to stop crates.io allowing new crates with underscores (assuming hyphens are preferred). |
dtolnay commentedJun 6, 2016
Crates.io currently accepts hyphens for crates that use underscores, both in the web interface and in the API.
Cargo does not, but should.