Skip to content
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
47 changes: 25 additions & 22 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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())?;
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/rust_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand All @@ -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", "")
Expand Down