Skip to content

Commit cc17afb

Browse files
committed
Auto merge of #9732 - djc:rust-version-docs, r=ehuss
Stabilize the rust-version field I've tried to make the documentation here fairly comprehensive. I've also updated the first version for the 2021 edition, which should now be stable pending substantial unforeseen changes. See #8072.
2 parents d555e49 + c43024f commit cc17afb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+235
-141
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
### Added
77

8+
- Added support for the [`rust-version`](https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-rust-version-field)
9+
field in a crate's metadata and the `--ignore-rust-version` command line option.
810
- Build scripts can now pass additional linker arguments for binaries or all
911
linkable targets. [docs](https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#outputs-of-the-build-script)
1012
[#9557](https://github.com/rust-lang/cargo/pull/9557)

src/cargo/core/features.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ impl Edition {
166166
match self {
167167
Edition2015 => None,
168168
Edition2018 => Some(semver::Version::new(1, 31, 0)),
169-
// FIXME: This will likely be 1.56, update when that seems more likely.
170-
Edition2021 => Some(semver::Version::new(1, 62, 0)),
169+
Edition2021 => Some(semver::Version::new(1, 56, 0)),
171170
}
172171
}
173172

@@ -396,7 +395,7 @@ features! {
396395
(unstable, strip, "", "reference/unstable.html#profile-strip-option"),
397396

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

401400
// Support for 2021 edition.
402401
(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/man/cargo-bench.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ target.
8383

8484
{{> options-target-triple }}
8585

86+
{{> options-ignore-rust-version }}
87+
8688
{{/options}}
8789

8890
### Output Options

src/doc/man/cargo-build.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ they have `required-features` that are missing.
3535

3636
{{> options-release }}
3737

38+
{{> options-ignore-rust-version }}
39+
3840
{{/options}}
3941

4042
### Output Options

src/doc/man/cargo-check.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ they have `required-features` that are missing.
4242

4343
{{> options-profile }}
4444

45+
{{> options-ignore-rust-version }}
46+
4547
{{/options}}
4648

4749
### Output Options

src/doc/man/cargo-doc.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ flag and will always document the given target.
6464

6565
{{> options-release }}
6666

67+
{{> options-ignore-rust-version }}
68+
6769
{{/options}}
6870

6971
### Output Options

src/doc/man/cargo-fix.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ When no target selection options are given, `cargo fix` will fix all targets
122122

123123
{{> options-profile }}
124124

125+
{{> options-ignore-rust-version }}
126+
125127
{{/options}}
126128

127129
### Output Options

src/doc/man/cargo-run.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Run the specified example.
5050

5151
{{> options-release }}
5252

53+
{{> options-ignore-rust-version }}
54+
5355
{{/options}}
5456

5557
### Output Options

0 commit comments

Comments
 (0)