Skip to content

Commit

Permalink
Use ToSemver more
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Dec 20, 2018
1 parent 7cbf886 commit cffd5b2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/cargo/core/package_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<'de> de::Deserialize<'de> for PackageId {
Some(s) => s,
None => return Err(de::Error::custom("invalid serialized PackageId")),
};
let version = semver::Version::parse(version).map_err(de::Error::custom)?;
let version = version.to_semver().map_err(de::Error::custom)?;
let url = match s.next() {
Some(s) => s,
None => return Err(de::Error::custom("invalid serialized PackageId")),
Expand Down
14 changes: 7 additions & 7 deletions src/cargo/core/package_id_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl PackageIdSpec {
let mut parts = spec.splitn(2, ':');
let name = parts.next().unwrap();
let version = match parts.next() {
Some(version) => Some(Version::parse(version)?),
Some(version) => Some(version.to_semver()?),
None => None,
};
validate_package_name(name, "pkgid", "")?;
Expand Down Expand Up @@ -274,7 +274,7 @@ impl<'de> de::Deserialize<'de> for PackageIdSpec {
mod tests {
use super::PackageIdSpec;
use crate::core::{PackageId, SourceId};
use semver::Version;
use crate::util::ToSemver;
use url::Url;

#[test]
Expand All @@ -289,15 +289,15 @@ mod tests {
"http://crates.io/foo#1.2.3",
PackageIdSpec {
name: "foo".to_string(),
version: Some(Version::parse("1.2.3").unwrap()),
version: Some("1.2.3".to_semver().unwrap()),
url: Some(Url::parse("http://crates.io/foo").unwrap()),
},
);
ok(
"http://crates.io/foo#bar:1.2.3",
PackageIdSpec {
name: "bar".to_string(),
version: Some(Version::parse("1.2.3").unwrap()),
version: Some("1.2.3".to_semver().unwrap()),
url: Some(Url::parse("http://crates.io/foo").unwrap()),
},
);
Expand All @@ -313,7 +313,7 @@ mod tests {
"crates.io/foo#1.2.3",
PackageIdSpec {
name: "foo".to_string(),
version: Some(Version::parse("1.2.3").unwrap()),
version: Some("1.2.3".to_semver().unwrap()),
url: Some(Url::parse("cargo://crates.io/foo").unwrap()),
},
);
Expand All @@ -329,7 +329,7 @@ mod tests {
"crates.io/foo#bar:1.2.3",
PackageIdSpec {
name: "bar".to_string(),
version: Some(Version::parse("1.2.3").unwrap()),
version: Some("1.2.3".to_semver().unwrap()),
url: Some(Url::parse("cargo://crates.io/foo").unwrap()),
},
);
Expand All @@ -345,7 +345,7 @@ mod tests {
"foo:1.2.3",
PackageIdSpec {
name: "foo".to_string(),
version: Some(Version::parse("1.2.3").unwrap()),
version: Some("1.2.3".to_semver().unwrap()),
url: None,
},
);
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::{env, fs};

use semver::{Version, VersionReq};
use semver::VersionReq;
use serde::{Deserialize, Serialize};
use tempfile::Builder as TempFileBuilder;

Expand All @@ -19,7 +19,7 @@ use crate::ops::{self, CompileFilter};
use crate::sources::{GitSource, PathSource, SourceConfigMap};
use crate::util::errors::{CargoResult, CargoResultExt};
use crate::util::paths;
use crate::util::{internal, Config};
use crate::util::{internal, Config, ToSemver};
use crate::util::{FileLock, Filesystem};

#[derive(Deserialize, Serialize)]
Expand Down Expand Up @@ -456,7 +456,7 @@ where
v
),
},
_ => match v.parse::<Version>() {
_ => match v.to_semver() {
Ok(v) => Some(format!("={}", v)),
Err(_) => {
let mut msg = format!(
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/sources/registry/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::core::dependency::Dependency;
use crate::core::{PackageId, SourceId, Summary};
use crate::sources::registry::RegistryData;
use crate::sources::registry::{RegistryPackage, INDEX_LOCK};
use crate::util::{internal, CargoResult, Config, Filesystem};
use crate::util::{internal, CargoResult, Config, Filesystem, ToSemver};

/// Crates.io treats hyphen and underscores as interchangeable
/// but, the index and old cargo do not. So the index must store uncanonicalized version
Expand Down Expand Up @@ -293,7 +293,7 @@ impl<'cfg> RegistryIndex<'cfg> {
let mut vers = p[name.len() + 1..].splitn(2, "->");
if dep
.version_req()
.matches(&Version::parse(vers.next().unwrap()).unwrap())
.matches(&vers.next().unwrap().to_semver().unwrap())
{
vers.next().unwrap() == s.version().to_string()
} else {
Expand Down

0 comments on commit cffd5b2

Please sign in to comment.