Skip to content

Update to semver 1.0.0 #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ keywords = ["version", "rustc"]
edition = "2018"

[dependencies]
semver = "0.11"
semver = "1.0"

[dev-dependencies]
doc-comment = "0.3"
24 changes: 9 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ use std::process::Command;
use std::{env, error, fmt, io, num, str};
use std::{ffi::OsString, str::FromStr};

use semver::{self, Identifier};
// Convenience re-export to allow version comparison without needing to add
// semver crate.
pub use semver::Version;
Expand Down Expand Up @@ -231,12 +230,12 @@ pub fn version_meta_for(verbose_version_string: &str) -> Result<VersionMeta> {
let release = expect_key("release", &map)?;
let semver: Version = release.parse()?;

let channel = match semver.pre.first() {
None => Channel::Stable,
Some(Identifier::AlphaNumeric(s)) if s == "dev" => Channel::Dev,
Some(Identifier::AlphaNumeric(s)) if s == "beta" => Channel::Beta,
Some(Identifier::AlphaNumeric(s)) if s == "nightly" => Channel::Nightly,
Some(x) => return Err(Error::UnknownPreReleaseTag(x.clone())),
let channel = match semver.pre.split('.').next().unwrap() {
"" => Channel::Stable,
"dev" => Channel::Dev,
"beta" => Channel::Beta,
"nightly" => Channel::Nightly,
x => return Err(Error::UnknownPreReleaseTag(x.to_owned())),
};

let commit_hash = expect_key_or_unknown("commit-hash", &map)?;
Expand Down Expand Up @@ -353,12 +352,10 @@ pub enum Error {
Utf8Error(str::Utf8Error),
/// The output of `rustc -vV` was not in the expected format.
UnexpectedVersionFormat,
/// An error occurred in parsing a `VersionReq`.
ReqParseError(semver::ReqParseError),
/// An error occurred in parsing the semver.
SemVerError(semver::SemVerError),
SemVerError(semver::Error),
/// The pre-release tag is unknown.
UnknownPreReleaseTag(Identifier),
UnknownPreReleaseTag(String),
/// An error occurred in parsing a `LlvmVersion`.
LlvmVersionError(LlvmVersionParseError),
}
Expand All @@ -377,7 +374,6 @@ impl fmt::Display for Error {
),
Utf8Error(_) => write!(f, "invalid UTF-8 output from `rustc -vV`"),
UnexpectedVersionFormat => write!(f, "unexpected `rustc -vV` format"),
ReqParseError(ref e) => write!(f, "error parsing version requirement: {}", e),
SemVerError(ref e) => write!(f, "error parsing version: {}", e),
UnknownPreReleaseTag(ref i) => write!(f, "unknown pre-release tag: {}", i),
LlvmVersionError(ref e) => write!(f, "error parsing LLVM's version: {}", e),
Expand All @@ -392,7 +388,6 @@ impl error::Error for Error {
CommandError { .. } => None,
Utf8Error(ref e) => Some(e),
UnexpectedVersionFormat => None,
ReqParseError(ref e) => Some(e),
SemVerError(ref e) => Some(e),
UnknownPreReleaseTag(_) => None,
LlvmVersionError(ref e) => Some(e),
Expand All @@ -414,8 +409,7 @@ macro_rules! impl_from {

impl_from! {
str::Utf8Error => Utf8Error,
semver::SemVerError => SemVerError,
semver::ReqParseError => ReqParseError,
semver::Error => SemVerError,
LlvmVersionParseError => LlvmVersionError,
}

Expand Down