Skip to content

Commit

Permalink
fix: matches_prerelease should be only used on OptVersionReq::Req
Browse files Browse the repository at this point in the history
  • Loading branch information
linyihai committed Aug 16, 2024
1 parent 2c27615 commit 32df76c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/cargo/util/semver_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ impl OptVersionReq {
pub fn is_locked(&self) -> bool {
matches!(self, OptVersionReq::Locked(..))
}

/// Gets the version to which this req is locked, if any.
pub fn locked_version(&self) -> Option<&Version> {
match self {
Expand All @@ -116,7 +115,7 @@ impl OptVersionReq {
/// The logic here is temporary, we'll have to consider more boundary conditions later,
/// 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() {
if version.is_prerelease() && matches!(self, OptVersionReq::Req(_)) {
let mut version = version.clone();
version.pre = semver::Prerelease::EMPTY;
return self.matches(&version);
Expand Down Expand Up @@ -251,9 +250,9 @@ mod matches_prerelease {
assert!(req.matches_prerelease(&to_ver));

let req = OptVersionReq::Locked(to_ver.clone(), req_ver.clone());
assert!(!req.matches_prerelease(&to_ver));
assert!(req.matches_prerelease(&to_ver));

let req = OptVersionReq::Locked(to_ver.clone(), req_ver.clone());
assert!(!req.matches_prerelease(&to_ver));
assert!(req.matches_prerelease(&to_ver));
}
}

0 comments on commit 32df76c

Please sign in to comment.