diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:42 +0000 |
commit | cec1877e180393eba0f6ddb0cf97bf3a791631c7 (patch) | |
tree | 47b4dac2a9dd9a40c30c251b4d4a72d7ccf77e9f /vendor/semver/src | |
parent | Adding debian version 1.74.1+dfsg1-1. (diff) | |
download | rustc-cec1877e180393eba0f6ddb0cf97bf3a791631c7.tar.xz rustc-cec1877e180393eba0f6ddb0cf97bf3a791631c7.zip |
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/semver/src')
-rw-r--r-- | vendor/semver/src/impls.rs | 4 | ||||
-rw-r--r-- | vendor/semver/src/lib.rs | 50 |
2 files changed, 51 insertions, 3 deletions
diff --git a/vendor/semver/src/impls.rs b/vendor/semver/src/impls.rs index c3b6c6013..cc4fd415f 100644 --- a/vendor/semver/src/impls.rs +++ b/vendor/semver/src/impls.rs @@ -38,13 +38,13 @@ impl Deref for BuildMetadata { impl PartialOrd for Prerelease { fn partial_cmp(&self, rhs: &Self) -> Option<Ordering> { - Some(Ord::cmp(self, rhs)) + Some(self.cmp(rhs)) } } impl PartialOrd for BuildMetadata { fn partial_cmp(&self, rhs: &Self) -> Option<Ordering> { - Some(Ord::cmp(self, rhs)) + Some(self.cmp(rhs)) } } diff --git a/vendor/semver/src/lib.rs b/vendor/semver/src/lib.rs index d2c4eb378..9fb125513 100644 --- a/vendor/semver/src/lib.rs +++ b/vendor/semver/src/lib.rs @@ -60,7 +60,7 @@ //! //! [Specifying Dependencies]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html -#![doc(html_root_url = "https://docs.rs/semver/1.0.18")] +#![doc(html_root_url = "https://docs.rs/semver/1.0.20")] #![cfg_attr(doc_cfg, feature(doc_cfg))] #![cfg_attr(all(not(feature = "std"), not(no_alloc_crate)), no_std)] #![cfg_attr(not(no_unsafe_op_in_unsafe_fn_lint), deny(unsafe_op_in_unsafe_fn))] @@ -102,6 +102,7 @@ mod serde; use crate::alloc::vec::Vec; use crate::identifier::Identifier; +use core::cmp::Ordering; use core::str::FromStr; #[allow(unused_imports)] @@ -431,6 +432,53 @@ impl Version { pub fn parse(text: &str) -> Result<Self, Error> { Version::from_str(text) } + + /// Compare the major, minor, patch, and pre-release value of two versions, + /// disregarding build metadata. Versions that differ only in build metadata + /// are considered equal. This comparison is what the SemVer spec refers to + /// as "precedence". + /// + /// # Example + /// + /// ``` + /// use semver::Version; + /// + /// let mut versions = [ + /// "1.20.0+c144a98".parse::<Version>().unwrap(), + /// "1.20.0".parse().unwrap(), + /// "1.0.0".parse().unwrap(), + /// "1.0.0-alpha".parse().unwrap(), + /// "1.20.0+bc17664".parse().unwrap(), + /// ]; + /// + /// // This is a stable sort, so it preserves the relative order of equal + /// // elements. The three 1.20.0 versions differ only in build metadata so + /// // they are not reordered relative to one another. + /// versions.sort_by(Version::cmp_precedence); + /// assert_eq!(versions, [ + /// "1.0.0-alpha".parse().unwrap(), + /// "1.0.0".parse().unwrap(), + /// "1.20.0+c144a98".parse().unwrap(), + /// "1.20.0".parse().unwrap(), + /// "1.20.0+bc17664".parse().unwrap(), + /// ]); + /// + /// // Totally order the versions, including comparing the build metadata. + /// versions.sort(); + /// assert_eq!(versions, [ + /// "1.0.0-alpha".parse().unwrap(), + /// "1.0.0".parse().unwrap(), + /// "1.20.0".parse().unwrap(), + /// "1.20.0+bc17664".parse().unwrap(), + /// "1.20.0+c144a98".parse().unwrap(), + /// ]); + /// ``` + pub fn cmp_precedence(&self, other: &Self) -> Ordering { + Ord::cmp( + &(self.major, self.minor, self.patch, &self.pre), + &(other.major, other.minor, other.patch, &other.pre), + ) + } } impl VersionReq { |