diff --git a/src/cargo/util/semver_eval_ext.rs b/src/cargo/util/semver_eval_ext.rs index a402f454412a..e73a46ee8d3e 100644 --- a/src/cargo/util/semver_eval_ext.rs +++ b/src/cargo/util/semver_eval_ext.rs @@ -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; } diff --git a/src/cargo/util/toml_mut/upgrade.rs b/src/cargo/util/toml_mut/upgrade.rs index b81f51ec5e3f..f50977641714 100644 --- a/src/cargo/util/toml_mut/upgrade.rs +++ b/src/cargo/util/toml_mut/upgrade.rs @@ -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. @@ -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::>()?; if comparators.is_empty() { @@ -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,