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

View File

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