diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/rustversion/src/bound.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustversion/src/bound.rs')
-rw-r--r-- | vendor/rustversion/src/bound.rs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/vendor/rustversion/src/bound.rs b/vendor/rustversion/src/bound.rs new file mode 100644 index 000000000..a667a5b0d --- /dev/null +++ b/vendor/rustversion/src/bound.rs @@ -0,0 +1,63 @@ +use crate::date::{self, Date}; +use crate::error::{Error, Result}; +use crate::iter::Iter; +use crate::release::{self, Release}; +use crate::time; +use crate::version::{Channel::*, Version}; +use proc_macro::{Group, TokenTree}; +use std::cmp::Ordering; + +pub enum Bound { + Nightly(Date), + Stable(Release), +} + +pub fn parse(paren: Group, iter: Iter) -> Result<Bound> { + if let Some(TokenTree::Literal(literal)) = iter.peek() { + let repr = literal.to_string(); + if repr.starts_with(|ch: char| ch.is_ascii_digit()) { + if repr.contains('.') { + return release::parse(paren, iter).map(Bound::Stable); + } else { + return date::parse(paren, iter).map(Bound::Nightly); + } + } + } + let msg = format!( + "expected rustc release number like 1.31, or nightly date like {}", + time::today(), + ); + Err(Error::group(paren, msg)) +} + +impl PartialEq<Bound> for Version { + fn eq(&self, rhs: &Bound) -> bool { + match rhs { + Bound::Nightly(date) => match self.channel { + Stable | Beta | Dev => false, + Nightly(nightly) => nightly == *date, + }, + Bound::Stable(release) => { + self.minor == release.minor + && release.patch.map_or(true, |patch| self.patch == patch) + } + } + } +} + +impl PartialOrd<Bound> for Version { + fn partial_cmp(&self, rhs: &Bound) -> Option<Ordering> { + match rhs { + Bound::Nightly(date) => match self.channel { + Stable | Beta => Some(Ordering::Less), + Nightly(nightly) => Some(nightly.cmp(date)), + Dev => Some(Ordering::Greater), + }, + Bound::Stable(release) => { + let version = (self.minor, self.patch); + let bound = (release.minor, release.patch.unwrap_or(0)); + Some(version.cmp(&bound)) + } + } + } +} |