Skip to content

Commit

Permalink
chore: deduplicate matches_greater
Browse files Browse the repository at this point in the history
  • Loading branch information
linyihai committed Aug 22, 2024
1 parent bdf19e0 commit de78ea3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/cargo/util/semver_eval_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn matches_exact(cmp: &Comparator, ver: &Version) -> bool {
}

// See https://github.com/dtolnay/semver/blob/69efd3cc770ead273a06ad1788477b3092996d29/src/eval.rs#L64-L88
fn matches_greater(cmp: &Comparator, ver: &Version) -> bool {
pub(crate) fn matches_greater(cmp: &Comparator, ver: &Version) -> bool {
if ver.major != cmp.major {
return ver.major > cmp.major;
}
Expand Down
33 changes: 3 additions & 30 deletions src/cargo/util/toml_mut/upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt::Display;

use crate::util::semver_eval_ext;
use crate::CargoResult;
use std::fmt::Display;

/// Upgrade an existing requirement to a new version.
/// Copied from cargo-edit.
Expand All @@ -19,7 +19,7 @@ pub(crate) fn upgrade_requirement(
.comparators
.into_iter()
// Don't downgrade if pre-release was used, see https://github.com/rust-lang/cargo/issues/14178 and https://github.com/rust-lang/cargo/issues/13290.
.filter(|p| p.pre.is_empty() || matches_greater(p, version))
.filter(|p| p.pre.is_empty() || semver_eval_ext::matches_greater(p, version))
.map(|p| set_comparator(p, version))
.collect::<CargoResult<_>>()?;
if comparators.is_empty() {
Expand Down Expand Up @@ -78,33 +78,6 @@ fn set_comparator(
}
}

// See https://github.com/dtolnay/semver/blob/69efd3cc770ead273a06ad1788477b3092996d29/src/eval.rs#L64-L88
fn matches_greater(cmp: &semver::Comparator, ver: &semver::Version) -> bool {
if ver.major != cmp.major {
return ver.major > cmp.major;
}

match cmp.minor {
None => return false,
Some(minor) => {
if ver.minor != minor {
return ver.minor > minor;
}
}
}

match cmp.patch {
None => return false,
Some(patch) => {
if ver.patch != patch {
return ver.patch > patch;
}
}
}

ver.pre > cmp.pre
}

fn assign_partial_req(
version: &semver::Version,
mut pred: semver::Comparator,
Expand Down

0 comments on commit de78ea3

Please sign in to comment.