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

"*" is not equal to any() #161

Closed
dtolnay opened this issue Nov 25, 2017 · 6 comments
Closed

"*" is not equal to any() #161

dtolnay opened this issue Nov 25, 2017 · 6 comments

Comments

@dtolnay
Copy link
Owner

dtolnay commented Nov 25, 2017

I would expect the following program to print * * true. Instead it prints * * false.

extern crate semver;
use semver::VersionReq;

fn main() {
    let any = VersionReq::any();
    let star = VersionReq::parse("*").unwrap();
    println!("{} {} {}", any, star, any == star);
}
@KodrAus
Copy link

KodrAus commented Nov 25, 2017

Looks like we might need to implement equality traits manually by calling matches instead of deriving them?

@connorkuehl
Copy link

connorkuehl commented Nov 27, 2017

I don't think there's anything wrong with the equality traits. It looks like VersionReq derives it all the way down.

I added:

println!("{:?}\n{:?}", any, star);

to @dtolnay's test program.

The output is interesting:

* * false
VersionReq { predicates: [] }
VersionReq { predicates: [Predicate { op: Wildcard(Major), major: 0, minor: None, patch: None, pre: [] }] }

Definitely not the same 😨, but it should be.

I've spent some time trying to debug this but rust-lldb is going to give me an actual heart palpation. I'm having a horrible time setting breakpoints. That's a rant for some place else, though.

I wonder if it could be something to do with the crate boundary between semver and semver_parser? From::from() for semver::VersionReq and semver_parser::VersionReq? That code looks fairly standard, though.

VersionReq::parse("*") should lead to a call to semver_parser::range::parse(input) which should return a VersionReq with an empty predicates vec (one that must be translated from a sever_parser::VersionReq into a semver::VersionReq. I'm inclined to believe we have a stowaway predicate somewhere around here. Unfortunately without my debugger actually being able to break on any of these I can't find exactly where that weird predicate is being inserted.

tl;dr -- VersionReq::parse("*") is producing an VersionReq with a phantom predicate; the "any" VersionReqs being considered here are not consistent with each other.

@agalakhov
Copy link

It's even worse: the star does not work as expected.

let req = VersionReq::parse("*").unwrap();
let vers = Version::parse("0.1.0-beta");
assert!(req.matches(&vers)); // ??? !!!

@udoprog
Copy link
Contributor

udoprog commented Nov 27, 2017

Hey,

The original equality issue is addressed in #151, and is also partly the motivation for why #159 was introduced.

Edit: original bug report filed in #150 which mentions this problem.

@matklad
Copy link
Contributor

matklad commented May 2, 2018

So, as pointed out by @agalakhov , * and any are indeed different, and to me it looks like this might be intentional?

The * is used for, at least in Cargo, "give me the latest version of a crate", where "latest" does not include prereleases. any is used internally to mean "I really don't care about version requirements at all, and prereleases are fine with me".

@dtolnay
Copy link
Owner Author

dtolnay commented May 25, 2021

This is fixed in 1.0.0. "Any" is no longer a thing, because there is no SemVer syntax that behaves that way. "Star" is a different thing and is exposed as https://docs.rs/semver/1.0.0-rc.1/semver/struct.VersionReq.html#associatedconstant.STAR. If someone needs the semantics of sometimes always matching everything, then they should use Option<VersionReq>, and .map_or(true, |req| req.matches(version)).

@dtolnay dtolnay closed this as completed May 25, 2021
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

No branches or pull requests

6 participants