Skip to content

Commit d783456

Browse files
committed
Stabilize rust-version
1 parent db3776c commit d783456

File tree

5 files changed

+23
-139
lines changed

5 files changed

+23
-139
lines changed

src/cargo/core/features.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ features! {
395395
(unstable, strip, "", "reference/unstable.html#profile-strip-option"),
396396

397397
// Specifying a minimal 'rust-version' attribute for crates
398-
(unstable, rust_version, "", "reference/unstable.html#rust-version"),
398+
(stable, rust_version, "1.56", "reference/manifest.html#the-rust-version-field"),
399399

400400
// Support for 2021 edition.
401401
(unstable, edition2021, "", "reference/unstable.html#edition-2021"),

src/cargo/util/command_prelude.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub trait AppExt: Sized {
218218
fn arg_ignore_rust_version(self) -> Self {
219219
self._arg(opt(
220220
"ignore-rust-version",
221-
"Ignore `rust-version` specification in packages (unstable)",
221+
"Ignore `rust-version` specification in packages",
222222
))
223223
}
224224

@@ -533,12 +533,6 @@ pub trait ArgMatchesExt {
533533
honor_rust_version: !self._is_present("ignore-rust-version"),
534534
};
535535

536-
if !opts.honor_rust_version {
537-
config
538-
.cli_unstable()
539-
.fail_if_stable_opt("--ignore-rust-version", 8072)?;
540-
}
541-
542536
if let Some(ws) = workspace {
543537
self.check_optional_opts(ws, &opts)?;
544538
} else if self.is_present_with_zero_values("package") {

src/cargo/util/toml/mod.rs

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,46 +1122,25 @@ impl TomlManifest {
11221122
}
11231123

11241124
let rust_version = if let Some(rust_version) = &project.rust_version {
1125-
if features.require(Feature::rust_version()).is_err() {
1126-
let mut msg =
1127-
"`rust-version` is not supported on this version of Cargo and will be ignored"
1128-
.to_string();
1129-
if config.nightly_features_allowed {
1130-
msg.push_str(
1131-
"\n\n\
1132-
consider adding `cargo-features = [\"rust-version\"]` to the manifest",
1133-
);
1134-
} else {
1135-
msg.push_str(
1136-
"\n\n\
1137-
this Cargo does not support nightly features, but if you\n\
1138-
switch to nightly channel you can add\n\
1139-
`cargo-features = [\"rust-version\"]` to enable this feature",
1140-
);
1141-
}
1142-
warnings.push(msg);
1143-
None
1144-
} else {
1145-
let req = match semver::VersionReq::parse(rust_version) {
1146-
// Exclude semver operators like `^` and pre-release identifiers
1147-
Ok(req) if rust_version.chars().all(|c| c.is_ascii_digit() || c == '.') => req,
1148-
_ => bail!("`rust-version` must be a value like \"1.32\""),
1149-
};
1150-
if let Some(first_version) = edition.first_version() {
1151-
let unsupported =
1152-
semver::Version::new(first_version.major, first_version.minor - 1, 9999);
1153-
if req.matches(&unsupported) {
1154-
bail!(
1155-
"rust-version {} is older than first version ({}) required by \
1156-
the specified edition ({})",
1157-
rust_version,
1158-
first_version,
1159-
edition,
1160-
)
1161-
}
1125+
let req = match semver::VersionReq::parse(rust_version) {
1126+
// Exclude semver operators like `^` and pre-release identifiers
1127+
Ok(req) if rust_version.chars().all(|c| c.is_ascii_digit() || c == '.') => req,
1128+
_ => bail!("`rust-version` must be a value like \"1.32\""),
1129+
};
1130+
if let Some(first_version) = edition.first_version() {
1131+
let unsupported =
1132+
semver::Version::new(first_version.major, first_version.minor - 1, 9999);
1133+
if req.matches(&unsupported) {
1134+
bail!(
1135+
"rust-version {} is older than first version ({}) required by \
1136+
the specified edition ({})",
1137+
rust_version,
1138+
first_version,
1139+
edition,
1140+
)
11621141
}
1163-
Some(rust_version.clone())
11641142
}
1143+
Some(rust_version.clone())
11651144
} else {
11661145
None
11671146
};

src/doc/src/reference/unstable.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ Each new feature described below should explain how to use it.
8989
* [Custom named profiles](#custom-named-profiles) — Adds custom named profiles in addition to the standard names.
9090
* [Profile `strip` option](#profile-strip-option) — Forces the removal of debug information and symbols from executables.
9191
* [per-package-target](#per-package-target) — Sets the `--target` to use for each individual package.
92-
* [rust-version](#rust-version) — Allows to declare the minimum supported Rust version.
9392
* [Edition 2021](#edition-2021) — Adds support for the 2021 Edition.
9493
* Information and metadata
9594
* [Build-plan](#build-plan) — Emits JSON information on which commands will be run.
@@ -1170,25 +1169,6 @@ cargo logout -Z credential-process
11701169
[crates.io]: https://crates.io/
11711170
[config file]: config.md
11721171

1173-
### rust-version
1174-
* RFC: [#2495](https://github.com/rust-lang/rfcs/blob/master/text/2495-min-rust-version.md)
1175-
* rustc Tracking Issue: [#65262](https://github.com/rust-lang/rust/issues/65262)
1176-
1177-
The `-Z rust-version` flag enables the reading of the `rust-version` field in the
1178-
Cargo manifest `package` section. This can be used by a package to state a minimal
1179-
version of the compiler required to build the package. An error is generated if
1180-
the version of rustc is older than the stated `rust-version`. The
1181-
`--ignore-rust-version` flag can be used to override the check.
1182-
1183-
```toml
1184-
cargo-features = ["rust-version"]
1185-
1186-
[package]
1187-
name = "mypackage"
1188-
version = "0.0.1"
1189-
rust-version = "1.42"
1190-
```
1191-
11921172
### edition 2021
11931173
* Tracking Issue: [rust-lang/rust#85811](https://github.com/rust-lang/rust/issues/85811)
11941174

tests/testsuite/rust_version.rs

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,12 @@
22
33
use cargo_test_support::{project, registry::Package};
44

5-
#[cargo_test]
6-
fn rust_version_gated() {
7-
project()
8-
.file(
9-
"Cargo.toml",
10-
r#"
11-
[package]
12-
name = "foo"
13-
version = "0.0.1"
14-
rust-version = "1.9999"
15-
"#,
16-
)
17-
.file("src/lib.rs", "")
18-
.build()
19-
.cargo("build")
20-
.masquerade_as_nightly_cargo()
21-
.with_stderr_contains(
22-
"warning: `rust-version` is not supported on this version of Cargo and will be ignored\
23-
\n\nconsider adding `cargo-features = [\"rust-version\"]` to the manifest",
24-
)
25-
.run();
26-
27-
project()
28-
.file(
29-
"Cargo.toml",
30-
r#"
31-
[package]
32-
name = "foo"
33-
version = "0.0.1"
34-
rust-version = "1.9999"
35-
"#,
36-
)
37-
.file("src/lib.rs", "")
38-
.build()
39-
.cargo("build")
40-
.with_stderr_contains(
41-
"warning: `rust-version` is not supported on this version of Cargo and will be ignored\
42-
\n\nthis Cargo does not support nightly features, but if you\n\
43-
switch to nightly channel you can add\n\
44-
`cargo-features = [\"rust-version\"]` to enable this feature",
45-
)
46-
.run();
47-
}
48-
495
#[cargo_test]
506
fn rust_version_satisfied() {
517
let p = project()
528
.file(
539
"Cargo.toml",
5410
r#"
55-
cargo-features = ["rust-version"]
56-
5711
[project]
5812
name = "foo"
5913
version = "0.0.1"
@@ -66,10 +20,8 @@ fn rust_version_satisfied() {
6620
.file("src/main.rs", "fn main() {}")
6721
.build();
6822

69-
p.cargo("build").masquerade_as_nightly_cargo().run();
70-
p.cargo("build --ignore-rust-version -Zunstable-options")
71-
.masquerade_as_nightly_cargo()
72-
.run();
23+
p.cargo("build").run();
24+
p.cargo("build --ignore-rust-version").run();
7325
}
7426

7527
#[cargo_test]
@@ -78,8 +30,6 @@ fn rust_version_bad_caret() {
7830
.file(
7931
"Cargo.toml",
8032
r#"
81-
cargo-features = ["rust-version"]
82-
8333
[project]
8434
name = "foo"
8535
version = "0.0.1"
@@ -92,7 +42,6 @@ fn rust_version_bad_caret() {
9242
.file("src/main.rs", "fn main() {}")
9343
.build()
9444
.cargo("build")
95-
.masquerade_as_nightly_cargo()
9645
.with_status(101)
9746
.with_stderr(
9847
"error: failed to parse manifest at `[..]`\n\n\
@@ -107,8 +56,6 @@ fn rust_version_bad_pre_release() {
10756
.file(
10857
"Cargo.toml",
10958
r#"
110-
cargo-features = ["rust-version"]
111-
11259
[project]
11360
name = "foo"
11461
version = "0.0.1"
@@ -121,7 +68,6 @@ fn rust_version_bad_pre_release() {
12168
.file("src/main.rs", "fn main() {}")
12269
.build()
12370
.cargo("build")
124-
.masquerade_as_nightly_cargo()
12571
.with_status(101)
12672
.with_stderr(
12773
"error: failed to parse manifest at `[..]`\n\n\
@@ -136,8 +82,6 @@ fn rust_version_bad_nonsense() {
13682
.file(
13783
"Cargo.toml",
13884
r#"
139-
cargo-features = ["rust-version"]
140-
14185
[project]
14286
name = "foo"
14387
version = "0.0.1"
@@ -150,7 +94,6 @@ fn rust_version_bad_nonsense() {
15094
.file("src/main.rs", "fn main() {}")
15195
.build()
15296
.cargo("build")
153-
.masquerade_as_nightly_cargo()
15497
.with_status(101)
15598
.with_stderr(
15699
"error: failed to parse manifest at `[..]`\n\n\
@@ -165,8 +108,6 @@ fn rust_version_too_high() {
165108
.file(
166109
"Cargo.toml",
167110
r#"
168-
cargo-features = ["rust-version"]
169-
170111
[project]
171112
name = "foo"
172113
version = "0.0.1"
@@ -180,22 +121,18 @@ fn rust_version_too_high() {
180121
.build();
181122

182123
p.cargo("build")
183-
.masquerade_as_nightly_cargo()
184124
.with_status(101)
185125
.with_stderr(
186126
"error: package `foo v0.0.1 ([..])` cannot be built because it requires \
187127
rustc 1.9876.0 or newer, while the currently active rustc version is [..]",
188128
)
189129
.run();
190-
p.cargo("build --ignore-rust-version -Zunstable-options")
191-
.masquerade_as_nightly_cargo()
192-
.run();
130+
p.cargo("build --ignore-rust-version").run();
193131
}
194132

195133
#[cargo_test]
196134
fn rust_version_dependency_fails() {
197135
Package::new("bar", "0.0.1")
198-
.cargo_feature("rust-version")
199136
.rust_version("1.2345.0")
200137
.file("src/lib.rs", "fn other_stuff() {}")
201138
.publish();
@@ -216,7 +153,6 @@ fn rust_version_dependency_fails() {
216153
.build();
217154

218155
p.cargo("build")
219-
.masquerade_as_nightly_cargo()
220156
.with_status(101)
221157
.with_stderr(
222158
" Updating `[..]` index\n \
@@ -226,9 +162,7 @@ fn rust_version_dependency_fails() {
226162
rustc 1.2345.0 or newer, while the currently active rustc version is [..]",
227163
)
228164
.run();
229-
p.cargo("build --ignore-rust-version -Zunstable-options")
230-
.masquerade_as_nightly_cargo()
231-
.run();
165+
p.cargo("build --ignore-rust-version").run();
232166
}
233167

234168
#[cargo_test]
@@ -237,8 +171,6 @@ fn rust_version_older_than_edition() {
237171
.file(
238172
"Cargo.toml",
239173
r#"
240-
cargo-features = ["rust-version"]
241-
242174
[project]
243175
name = "foo"
244176
version = "0.0.1"
@@ -252,7 +184,6 @@ fn rust_version_older_than_edition() {
252184
.file("src/main.rs", "fn main() {}")
253185
.build()
254186
.cargo("build")
255-
.masquerade_as_nightly_cargo()
256187
.with_status(101)
257188
.with_stderr_contains(" rust-version 1.1 is older than first version (1.31.0) required by the specified edition (2018)",
258189
)

0 commit comments

Comments
 (0)