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

src/doc/man/cargo-rustc.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ binary and library targets of the selected package.
4747

4848
{{> options-release }}
4949

50+
{{> options-ignore-rust-version }}
51+
5052
{{/options}}
5153

5254
### Output Options

src/doc/man/cargo-rustdoc.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ if its name is the same as the lib target. Binaries are skipped if they have
6262

6363
{{> options-release }}
6464

65+
{{> options-ignore-rust-version }}
66+
6567
{{/options}}
6668

6769
### Output Options

src/doc/man/cargo-test.md

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

103103
{{> options-release }}
104104

105+
{{> options-ignore-rust-version }}
106+
105107
{{/options}}
106108

107109
### Output Options

src/doc/man/generated_txt/cargo-bench.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ OPTIONS
202202
<https://doc.rust-lang.org/cargo/guide/build-cache.html>
203203
documentation for more details.
204204

205+
--ignore-rust-version
206+
Benchmark the target even if the selected Rust compiler is older
207+
than the required Rust version as configured in the project's
208+
rust-version field.
209+
205210
Output Options
206211
--target-dir directory
207212
Directory for all generated artifacts and intermediate files. May

src/doc/man/generated_txt/cargo-build.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ OPTIONS
146146
Build optimized artifacts with the release profile. See the PROFILES
147147
section for details on how this affects profile selection.
148148

149+
--ignore-rust-version
150+
Build the target even if the selected Rust compiler is older than
151+
the required Rust version as configured in the project's
152+
rust-version field.
153+
149154
Output Options
150155
--target-dir directory
151156
Directory for all generated artifacts and intermediate files. May

src/doc/man/generated_txt/cargo-check.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ OPTIONS
158158
have it check unit tests which are usually excluded via the cfg
159159
attribute. This does not change the actual profile used.
160160

161+
--ignore-rust-version
162+
Check the target even if the selected Rust compiler is older than
163+
the required Rust version as configured in the project's
164+
rust-version field.
165+
161166
Output Options
162167
--target-dir directory
163168
Directory for all generated artifacts and intermediate files. May

src/doc/man/generated_txt/cargo-doc.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ OPTIONS
123123
Document optimized artifacts with the release profile. See the
124124
PROFILES section for details on how this affects profile selection.
125125

126+
--ignore-rust-version
127+
Document the target even if the selected Rust compiler is older than
128+
the required Rust version as configured in the project's
129+
rust-version field.
130+
126131
Output Options
127132
--target-dir directory
128133
Directory for all generated artifacts and intermediate files. May

src/doc/man/generated_txt/cargo-fix.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ OPTIONS
231231
it fix unit tests which are usually excluded via the cfg attribute.
232232
This does not change the actual profile used.
233233

234+
--ignore-rust-version
235+
Fix the target even if the selected Rust compiler is older than the
236+
required Rust version as configured in the project's rust-version
237+
field.
238+
234239
Output Options
235240
--target-dir directory
236241
Directory for all generated artifacts and intermediate files. May

src/doc/man/generated_txt/cargo-run.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ OPTIONS
7575
Run optimized artifacts with the release profile. See the PROFILES
7676
section for details on how this affects profile selection.
7777

78+
--ignore-rust-version
79+
Run the target even if the selected Rust compiler is older than the
80+
required Rust version as configured in the project's rust-version
81+
field.
82+
7883
Output Options
7984
--target-dir directory
8085
Directory for all generated artifacts and intermediate files. May

src/doc/man/generated_txt/cargo-rustc.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ OPTIONS
137137
Build optimized artifacts with the release profile. See the PROFILES
138138
section for details on how this affects profile selection.
139139

140+
--ignore-rust-version
141+
Build the target even if the selected Rust compiler is older than
142+
the required Rust version as configured in the project's
143+
rust-version field.
144+
140145
Output Options
141146
--target-dir directory
142147
Directory for all generated artifacts and intermediate files. May

src/doc/man/generated_txt/cargo-rustdoc.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ OPTIONS
146146
Document optimized artifacts with the release profile. See the
147147
PROFILES section for details on how this affects profile selection.
148148

149+
--ignore-rust-version
150+
Document the target even if the selected Rust compiler is older than
151+
the required Rust version as configured in the project's
152+
rust-version field.
153+
149154
Output Options
150155
--target-dir directory
151156
Directory for all generated artifacts and intermediate files. May

src/doc/man/generated_txt/cargo-test.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ OPTIONS
223223
Test optimized artifacts with the release profile. See the PROFILES
224224
section for details on how this affects profile selection.
225225

226+
--ignore-rust-version
227+
Test the target even if the selected Rust compiler is older than the
228+
required Rust version as configured in the project's rust-version
229+
field.
230+
226231
Output Options
227232
--target-dir directory
228233
Directory for all generated artifacts and intermediate files. May
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{{#option "`--ignore-rust-version`"}}
2+
{{actionverb}} the target even if the selected Rust compiler is older than the
3+
required Rust version as configured in the project's `rust-version` field.
4+
{{/option}}

src/doc/src/commands/cargo-bench.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ target artifacts are placed in a separate directory. See the
245245

246246

247247

248+
<dt class="option-term" id="option-cargo-bench---ignore-rust-version"><a class="option-anchor" href="#option-cargo-bench---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
249+
<dd class="option-desc">Benchmark the target even if the selected Rust compiler is older than the
250+
required Rust version as configured in the project's <code>rust-version</code> field.</dd>
251+
252+
253+
248254
</dl>
249255

250256
### Output Options

src/doc/src/commands/cargo-build.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ selection.</dd>
188188

189189

190190

191+
<dt class="option-term" id="option-cargo-build---ignore-rust-version"><a class="option-anchor" href="#option-cargo-build---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
192+
<dd class="option-desc">Build the target even if the selected Rust compiler is older than the
193+
required Rust version as configured in the project's <code>rust-version</code> field.</dd>
194+
195+
196+
191197
</dl>
192198

193199
### Output Options

src/doc/src/commands/cargo-check.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ used.</dd>
202202

203203

204204

205+
<dt class="option-term" id="option-cargo-check---ignore-rust-version"><a class="option-anchor" href="#option-cargo-check---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
206+
<dd class="option-desc">Check the target even if the selected Rust compiler is older than the
207+
required Rust version as configured in the project's <code>rust-version</code> field.</dd>
208+
209+
210+
205211
</dl>
206212

207213
### Output Options

src/doc/src/commands/cargo-doc.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ selection.</dd>
161161

162162

163163

164+
<dt class="option-term" id="option-cargo-doc---ignore-rust-version"><a class="option-anchor" href="#option-cargo-doc---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
165+
<dd class="option-desc">Document the target even if the selected Rust compiler is older than the
166+
required Rust version as configured in the project's <code>rust-version</code> field.</dd>
167+
168+
169+
164170
</dl>
165171

166172
### Output Options

src/doc/src/commands/cargo-fix.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ used.</dd>
282282

283283

284284

285+
<dt class="option-term" id="option-cargo-fix---ignore-rust-version"><a class="option-anchor" href="#option-cargo-fix---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
286+
<dd class="option-desc">Fix the target even if the selected Rust compiler is older than the
287+
required Rust version as configured in the project's <code>rust-version</code> field.</dd>
288+
289+
290+
285291
</dl>
286292

287293
### Output Options

src/doc/src/commands/cargo-run.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ selection.</dd>
106106

107107

108108

109+
<dt class="option-term" id="option-cargo-run---ignore-rust-version"><a class="option-anchor" href="#option-cargo-run---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
110+
<dd class="option-desc">Run the target even if the selected Rust compiler is older than the
111+
required Rust version as configured in the project's <code>rust-version</code> field.</dd>
112+
113+
114+
109115
</dl>
110116

111117
### Output Options

src/doc/src/commands/cargo-rustc.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ selection.</dd>
175175

176176

177177

178+
<dt class="option-term" id="option-cargo-rustc---ignore-rust-version"><a class="option-anchor" href="#option-cargo-rustc---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
179+
<dd class="option-desc">Build the target even if the selected Rust compiler is older than the
180+
required Rust version as configured in the project's <code>rust-version</code> field.</dd>
181+
182+
183+
178184
</dl>
179185

180186
### Output Options

0 commit comments

Comments
 (0)