Skip to content

Commit c5f7fa1

Browse files
committed
Auto merge of #9115 - djc:fix-msrv-handling, r=ehuss
Don't try to parse MSRV if feature is not enabled `@ehuss` is something like this what you had in mind? Should we add tests to make sure this works correctly?
2 parents 8a3361c + 040d27f commit c5f7fa1

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ impl TomlManifest {
10581058
Edition::Edition2015
10591059
};
10601060

1061-
if let Some(rust_version) = &project.rust_version {
1061+
let rust_version = if let Some(rust_version) = &project.rust_version {
10621062
if features.require(Feature::rust_version()).is_err() {
10631063
let mut msg =
10641064
"`rust-version` is not supported on this version of Cargo and will be ignored"
@@ -1077,28 +1077,31 @@ impl TomlManifest {
10771077
);
10781078
}
10791079
warnings.push(msg);
1080-
}
1081-
1082-
let req = match semver::VersionReq::parse(rust_version) {
1083-
// Exclude semver operators like `^` and pre-release identifiers
1084-
Ok(req) if rust_version.chars().all(|c| c.is_ascii_digit() || c == '.') => req,
1085-
_ => bail!("`rust-version` must be a value like \"1.32\""),
1086-
};
1087-
1088-
if let Some(first_version) = edition.first_version() {
1089-
let unsupported =
1090-
semver::Version::new(first_version.major, first_version.minor - 1, 9999);
1091-
if req.matches(&unsupported) {
1092-
bail!(
1093-
"rust-version {} is older than first version ({}) required by \
1094-
the specified edition ({})",
1095-
rust_version,
1096-
first_version,
1097-
edition,
1098-
)
1080+
None
1081+
} else {
1082+
let req = match semver::VersionReq::parse(rust_version) {
1083+
// Exclude semver operators like `^` and pre-release identifiers
1084+
Ok(req) if rust_version.chars().all(|c| c.is_ascii_digit() || c == '.') => req,
1085+
_ => bail!("`rust-version` must be a value like \"1.32\""),
1086+
};
1087+
if let Some(first_version) = edition.first_version() {
1088+
let unsupported =
1089+
semver::Version::new(first_version.major, first_version.minor - 1, 9999);
1090+
if req.matches(&unsupported) {
1091+
bail!(
1092+
"rust-version {} is older than first version ({}) required by \
1093+
the specified edition ({})",
1094+
rust_version,
1095+
first_version,
1096+
edition,
1097+
)
1098+
}
10991099
}
1100+
Some(rust_version.clone())
11001101
}
1101-
}
1102+
} else {
1103+
None
1104+
};
11021105

11031106
if project.metabuild.is_some() {
11041107
features.require(Feature::metabuild())?;
@@ -1339,7 +1342,7 @@ impl TomlManifest {
13391342
workspace_config,
13401343
features,
13411344
edition,
1342-
project.rust_version.clone(),
1345+
rust_version,
13431346
project.im_a_teapot,
13441347
project.default_run.clone(),
13451348
Rc::clone(me),

tests/testsuite/rust_version.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn rust_version_gated() {
1111
[package]
1212
name = "foo"
1313
version = "0.0.1"
14-
rust-version = "1.17"
14+
rust-version = "1.9999"
1515
"#,
1616
)
1717
.file("src/lib.rs", "")
@@ -31,7 +31,7 @@ fn rust_version_gated() {
3131
[package]
3232
name = "foo"
3333
version = "0.0.1"
34-
rust-version = "1.17"
34+
rust-version = "1.9999"
3535
"#,
3636
)
3737
.file("src/lib.rs", "")

0 commit comments

Comments
 (0)