Don't try to parse MSRV if feature is not enabled

This commit is contained in:
Dirkjan Ochtman 2021-01-30 16:33:54 +01:00
parent 8a3361c126
commit 040d27f39d
2 changed files with 27 additions and 24 deletions

View File

@ -1058,7 +1058,7 @@ impl TomlManifest {
Edition::Edition2015
};
if let Some(rust_version) = &project.rust_version {
let rust_version = if let Some(rust_version) = &project.rust_version {
if features.require(Feature::rust_version()).is_err() {
let mut msg =
"`rust-version` is not supported on this version of Cargo and will be ignored"
@ -1077,28 +1077,31 @@ impl TomlManifest {
);
}
warnings.push(msg);
}
let req = match semver::VersionReq::parse(rust_version) {
// Exclude semver operators like `^` and pre-release identifiers
Ok(req) if rust_version.chars().all(|c| c.is_ascii_digit() || c == '.') => req,
_ => bail!("`rust-version` must be a value like \"1.32\""),
};
if let Some(first_version) = edition.first_version() {
let unsupported =
semver::Version::new(first_version.major, first_version.minor - 1, 9999);
if req.matches(&unsupported) {
bail!(
"rust-version {} is older than first version ({}) required by \
the specified edition ({})",
rust_version,
first_version,
edition,
)
None
} else {
let req = match semver::VersionReq::parse(rust_version) {
// Exclude semver operators like `^` and pre-release identifiers
Ok(req) if rust_version.chars().all(|c| c.is_ascii_digit() || c == '.') => req,
_ => bail!("`rust-version` must be a value like \"1.32\""),
};
if let Some(first_version) = edition.first_version() {
let unsupported =
semver::Version::new(first_version.major, first_version.minor - 1, 9999);
if req.matches(&unsupported) {
bail!(
"rust-version {} is older than first version ({}) required by \
the specified edition ({})",
rust_version,
first_version,
edition,
)
}
}
Some(rust_version.clone())
}
}
} else {
None
};
if project.metabuild.is_some() {
features.require(Feature::metabuild())?;
@ -1339,7 +1342,7 @@ impl TomlManifest {
workspace_config,
features,
edition,
project.rust_version.clone(),
rust_version,
project.im_a_teapot,
project.default_run.clone(),
Rc::clone(me),

View File

@ -11,7 +11,7 @@ fn rust_version_gated() {
[package]
name = "foo"
version = "0.0.1"
rust-version = "1.17"
rust-version = "1.9999"
"#,
)
.file("src/lib.rs", "")
@ -31,7 +31,7 @@ fn rust_version_gated() {
[package]
name = "foo"
version = "0.0.1"
rust-version = "1.17"
rust-version = "1.9999"
"#,
)
.file("src/lib.rs", "")