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

Change type of Package.rust_version from VersionReq to Version #244

Merged
merged 1 commit into from
Jul 20, 2023

Conversation

not-my-profile
Copy link
Contributor

As per the Cargo Book1 the rust-version must:

be a bare version number with two or three components;
it cannot include semver operators or pre-release identifiers.

VersionReq therefore obviously is the wrong type since it describes2:

the intersection of some version comparators such as >=1.2.3, <1.8

It doesn't make much sense to deserialize strings that explicitly "cannot include semver operators" as a vector of comparison operators.

While the Version type's Deserialize implementation requires three components, we can just use a custom deserialize function to deserialize 1.2 as 1.2.0. This commit introduces such.

@oli-obk
Copy link
Owner

oli-obk commented Jul 20, 2023

deserialize 1.2 as 1.2.0.

Does cargo metadata actually get such truncated version numbers? I'd have hoped cargo emits full versions, even if it is more lenient in Cargo.toml

@not-my-profile
Copy link
Contributor Author

not-my-profile commented Jul 20, 2023

Yes it does. I tested it ... cargo metadata currently does not normalize such truncated version numbers in its output.

As per the Cargo Book[1] the `rust-version` must:

> be a bare version number with two or three components;
> it cannot include semver operators or pre-release identifiers.

VersionReq therefore obviously is the wrong type since it describes[2]:

> the intersection of some version comparators such as `>=1.2.3, <1.8`

It doesn't make much sense to deserialize strings that explicitly
"cannot include semver operators" as a vector of comparison operators.

While the Version type's Deserialize implementation requires three
components, we can just use a custom deserialize function to
deserialize 1.2 as 1.2.0. This commit introduces such.

[1]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-rust-version-field
[2]: https://docs.rs/semver/1.0.7/semver/struct.VersionReq.html
@oli-obk oli-obk merged commit 9595159 into oli-obk:main Jul 20, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants