Skip to content

Commit

Permalink
fix: Matching of precise prerelease versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
torhovland committed Jul 1, 2024
1 parent 13abe15 commit de1a4a2
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/cargo/util/semver_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,15 @@ impl OptVersionReq {
/// and we're not sure if this part of the functionality should be implemented in semver or cargo.
pub fn matches_prerelease(&self, version: &Version) -> bool {
if version.is_prerelease() {
let mut version = version.clone();
version.pre = semver::Prerelease::EMPTY;
return self.matches(&version);
// Only in the case of "ordinary" version requirements with pre-release
// versions do we need to help the version matching. In the case of Any,
// Locked, or Precise, the `matches()` function is already doing the
// correct handling.
if let OptVersionReq::Req(_) = self {
let mut version = version.clone();
version.pre = semver::Prerelease::EMPTY;
return self.matches(&version);
}
}
self.matches(version)
}
Expand Down Expand Up @@ -247,10 +253,6 @@ mod matches_prerelease {
let version = Version::parse("1.2.3-pre").unwrap();
let matched =
OptVersionReq::Precise(version.clone(), version_req).matches_prerelease(&version);

assert!(!matched, "this is wrong");

// FIXME: See https://github.com/rust-lang/cargo/issues/12425#issuecomment-2186198258
// assert!(matched, "a version must match its own precise requirement");
assert!(matched, "a version must match its own precise requirement");
}
}

0 comments on commit de1a4a2

Please sign in to comment.