diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index b3d379c41be1..c391c844bc55 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -6,7 +6,7 @@ use anyhow::format_err; use cargo::core::{GitReference, SourceId, Workspace}; use cargo::ops; use cargo::util::IntoUrl; -use cargo::util_semver::VersionExt; +use cargo::util::VersionExt; use cargo::CargoResult; use itertools::Itertools; use semver::VersionReq; diff --git a/src/cargo/core/resolver/errors.rs b/src/cargo/core/resolver/errors.rs index f3e72c51bb1f..4ecce02b5f09 100644 --- a/src/cargo/core/resolver/errors.rs +++ b/src/cargo/core/resolver/errors.rs @@ -4,8 +4,7 @@ use std::task::Poll; use crate::core::{Dependency, PackageId, Registry, Summary}; use crate::sources::source::QueryKind; use crate::util::edit_distance::edit_distance; -use crate::util::{Config, OptVersionReq}; -use crate::util_semver::VersionExt; +use crate::util::{Config, OptVersionReq, VersionExt}; use anyhow::Error; use super::context::Context; diff --git a/src/cargo/util/mod.rs b/src/cargo/util/mod.rs index e5ecd077fd73..12d8e6afdd77 100644 --- a/src/cargo/util/mod.rs +++ b/src/cargo/util/mod.rs @@ -22,7 +22,7 @@ pub use self::lockserver::{LockServer, LockServerClient, LockServerStarted}; pub use self::progress::{Progress, ProgressStyle}; pub use self::queue::Queue; pub use self::rustc::Rustc; -pub use self::semver_ext::OptVersionReq; +pub use self::semver_ext::{OptVersionReq, VersionExt}; pub use self::vcs::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo}; pub use self::workspace::{ add_path_args, path_args, print_available_benches, print_available_binaries, diff --git a/src/cargo/util/semver_ext.rs b/src/cargo/util/semver_ext.rs index 854fab6c8a2b..fed957ef7d95 100644 --- a/src/cargo/util/semver_ext.rs +++ b/src/cargo/util/semver_ext.rs @@ -1,8 +1,30 @@ use std::fmt::{self, Display}; -use semver::{Op, Version, VersionReq}; +use semver::{Comparator, Op, Version, VersionReq}; -use crate::util_semver::VersionExt as _; +pub trait VersionExt { + fn is_prerelease(&self) -> bool; + + fn to_exact_req(&self) -> VersionReq; +} + +impl VersionExt for Version { + fn is_prerelease(&self) -> bool { + !self.pre.is_empty() + } + + fn to_exact_req(&self) -> VersionReq { + VersionReq { + comparators: vec![Comparator { + op: Op::Exact, + major: self.major, + minor: Some(self.minor), + patch: Some(self.patch), + pre: self.pre.clone(), + }], + } + } +} #[derive(PartialEq, Eq, Hash, Clone, Debug)] pub enum OptVersionReq { diff --git a/src/cargo/util_semver.rs b/src/cargo/util_semver.rs index a84c9ee582ea..9670bd877644 100644 --- a/src/cargo/util_semver.rs +++ b/src/cargo/util_semver.rs @@ -1,32 +1,8 @@ use std::fmt::{self, Display}; -use semver::{Comparator, Op, Version, VersionReq}; +use semver::{Comparator, Version, VersionReq}; use serde_untagged::UntaggedEnumVisitor; -pub trait VersionExt { - fn is_prerelease(&self) -> bool; - - fn to_exact_req(&self) -> VersionReq; -} - -impl VersionExt for Version { - fn is_prerelease(&self) -> bool { - !self.pre.is_empty() - } - - fn to_exact_req(&self) -> VersionReq { - VersionReq { - comparators: vec![Comparator { - op: Op::Exact, - major: self.major, - minor: Some(self.minor), - patch: Some(self.patch), - pre: self.pre.clone(), - }], - } - } -} - #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug)] pub struct PartialVersion { pub major: u64,