dtolnay / semver

Parser and evaluator for Cargo's flavor of Semantic Versioning

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wildcard VersionReq alongside other requirements

jonhoo opened this issue · comments

I honestly don't know if this is correct behavior or not, but it seems like it should be accepted:

semver::VersionReq::parse("*, 0.20.0-any").unwrap();

gives

Error("unexpected character after wildcard in version req")

The intent of the version requirement specifier is to match any released version and any pre-release version of 0.20.0 since pre-releases aren't matched by *.

Reversing the order gives a different error which makes it seem like * is only permitted when used alone:

semver::VersionReq::parse("0.20.0-any, *").unwrap();

gives

Error("unexpected character '*' while parsing major version number")

You should go to the Cargo team about syntax changes. This is intentionally not accepted right now. A Cargo RFC may be required.

The intent of the version requirement specifier is to match any released version and any pre-release version of 0.20.0 since pre-releases aren't matched by *.

Note that this is not what comma means. Comma roughly represents intersection, not union. That is why e.g. >=2, <4 does not match every major version. It would not be my expectation that *, 0.20.0-any has a meaning that is different from ^0.20.0-any.

You should go to the Cargo team about syntax changes. This is intentionally not accepted right now. A Cargo RFC may be required.

Fair enough. I wonder if the error could be better though — something along the lines of "wildcard specifiers (*) are only accepted when used on their own".

The intent of the version requirement specifier is to match any released version and any pre-release version of 0.20.0 since pre-releases aren't matched by *.

Note that this is not what comma means. Comma roughly represents intersection, not union. That is why e.g. >=2, <4 does not match every major version. It would not be my expectation that *, 0.20.0-any has a meaning that is different from ^0.20.0-any.

Ooof, of course, you're right. The end of a day that was too long :) And also suggests some additional clean-up I'll have to do at work tomorrow 😅 I suppose there isn't really a way to specify union today except by keeping multiple VersionReqs and using .iter().any(|vr| vr.matches(...)).

Reopening for #266 (comment).