-
Couldn't load subscription status.
- Fork 2.7k
Allow integral edition specifier #5617
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
Conversation
|
(rust_highfive has picked a reviewer for you, use r? to override) |
|
r? @matklad as acrichto is not available atm. |
| pub enum StringOrU32 { | ||
| String(String), | ||
| U32(u32), | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the same code for TomlOptLevel as well? It already does something similar, but in a slightly different way. Maybe it's better even to go in the opposite direction and reuse that logic here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, or perhaps the best way to rewrite both with #[serde(deserialize_with="string_or_int")]?
|
An excellent idea! Let's add a test for it here: cargo/tests/testsuite/package.rs Line 1103 in f35302c
And let's use this better way in the docs: https://github.com/rust-lang/cargo/blob/9f097787b04b06cdde4fc42b26a531b22c1b37a6/src/doc/src/reference/unstable.md#edition @rust-lang/cargo anyone sees any drawbacks here? Seems relatively minor and robust to me, but, because it affects Cargo's public interface, I'd like to double-check with you. cc @steveklabnik: a small thing, but it affects how your first Cargo.toml looks like |
|
@matklad The PR already changes the docs and it also adds a test. Should I do it differently? As for the suggestion about the serialization, sure can do it. |
|
This adds 87 lines of code to save two characters. (Okay, some of it is whitespace, and some of it is tests, but the point is, you wouldn't need those tests without this.) Is this actually worth it? I'm not convinced. |
|
I prefer not to support integers in this position for consistency. We don't support integers or floating points as version constraints, even though that would have the same motivation. These fields are strings. |
|
Semver versions are Editions are different. For them we only allow 2015 and 2018. The entire value space can be represented as integers. Not sure about future decisions, but if that value space is extended in a fashion that does not allow integer representation, we can still use strings. This PR only allows integers to be used, it does not mandate their use. @steveklabnik I don't think that point is really valid anyway (how large is the impl Trait in argument position patch xD), but applying @matklad 's suggestion makes my patch much smaller. Just watch! |
Apparently, it's too early in the morning for me to do code reviews =/ Tests and docs look great to me now that I've actually saw them! To clarify why I think this is a good idea: Currently, edition numbers are integers. I think we might introduce something like Note that we already support mixed typed in other places in Cargo.toml, for example, As for consistency with versions/version requirements I agree with @est31: we conceptually use SemVer for package versions and integers for edition versions, so, to me, it doesn't seem that these are the same thing. |
|
I think its fairly likely we will someday have an edition which we want to give a non-integral name. Early versions of the preview proposal used the syntax Unless the type can encode all forms, I'd rather not support it. If I agreed that editions would always be an integral number, I'd be for this (well, really, I'd question the choice to support strings in that case). But I think editions can be named arbitrary strings. The biggest problem for me is for a user who is new to TOML, and the way this could confuse them into thinking TOML supports bare words in value position (since it does support them in key position). Even more generally, I'd rather keep our use of TOML as "simply typed" as possible and avoid supporting multiple types without strong motivation (the support for both strings and objects for dependencies members is an example that pulls its weight). |
|
Hrmmm I've tried doing the fn string_or_int<'de, T, D>(deserializer: D) -> Result<T, D::Error>
where
T: Deserialize<'de> + FromStr<Err = ()>,
D: Deserializer<'de>,
{and keeping |
|
To further reduce code size, I could remove the where clauses and instead put stuff into the pointy brackets like: fn visit_i64<E: de::Error>(self, u: i64) -> Result<Self::Value, E> {
Ok(StringOrU32::U32(u as u32))
}
fn visit_str<E: de::Error>(self, s: &str) -> Result<Self::Value, E> {
Ok(StringOrU32::String(s.to_string()))
} |
It seems that I personally feel much more comfortable with allowing "elaborately typed" toml values. I'd like to allow specifying integers as integers, so that that the user does not have to think "why I need to quote 2018? It is a number, TOML support numbers". Note that we already support union types in some lesser-obvious places than dependencies: Let's talk about this briefly during the next Cargo meeting? I don't have super strong feelings here, but I do find number-represented-as-string weird and I now totally see that this is not as clear-cut as I've initially thought :) |
|
@matklad you have added the nominated label. Has this PR been talked about in the cargo team? |
|
Nope, we've run out of time :( |
|
Personally, I'm entirely in favor of this. Current editions use numbers, future editions will likely use numbers, and this makes Cargo accept numbers so people don't have to give advice like "just put edition equals 2018 in your |
|
The period of my contributions to Rust upstream has reached an end. Thus I'm unable to continue my work on this. I still think something like this is a great addition. I urge anyone interested in this change to adopt and continue it from here on. Thanks. |
|
Reopening this as I think it remains valuable. Thank you for your contributions, @est31. |
|
I'm gonna close this for now as we haven't had a chance to talk about this in rust-lang/cargo for awhile now, but we can always reopen if this comes back up! |
|
@alexcrichton please don't reopen this, as I won't maintain it any more, sorry. If you still want this please open a separate PR! thanks. |
This allows for more ergonomic edition switching. Instead of
edition = "2018"you can now doedition = 2018which is 2 characters less. The string version is still allowed.