Skip to content

Commit de1a4a2

Browse files
committed
fix: Matching of precise prerelease versions.
1 parent 13abe15 commit de1a4a2

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/cargo/util/semver_ext.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,15 @@ impl OptVersionReq {
117117
/// and we're not sure if this part of the functionality should be implemented in semver or cargo.
118118
pub fn matches_prerelease(&self, version: &Version) -> bool {
119119
if version.is_prerelease() {
120-
let mut version = version.clone();
121-
version.pre = semver::Prerelease::EMPTY;
122-
return self.matches(&version);
120+
// Only in the case of "ordinary" version requirements with pre-release
121+
// versions do we need to help the version matching. In the case of Any,
122+
// Locked, or Precise, the `matches()` function is already doing the
123+
// correct handling.
124+
if let OptVersionReq::Req(_) = self {
125+
let mut version = version.clone();
126+
version.pre = semver::Prerelease::EMPTY;
127+
return self.matches(&version);
128+
}
123129
}
124130
self.matches(version)
125131
}
@@ -247,10 +253,6 @@ mod matches_prerelease {
247253
let version = Version::parse("1.2.3-pre").unwrap();
248254
let matched =
249255
OptVersionReq::Precise(version.clone(), version_req).matches_prerelease(&version);
250-
251-
assert!(!matched, "this is wrong");
252-
253-
// FIXME: See https://github.com/rust-lang/cargo/issues/12425#issuecomment-2186198258
254-
// assert!(matched, "a version must match its own precise requirement");
256+
assert!(matched, "a version must match its own precise requirement");
255257
}
256258
}

0 commit comments

Comments
 (0)