Skip to content

Commit 902487a

Browse files
authored
Rollup merge of rust-lang#123501 - Urgau:stabilize-check-cfg, r=petrochenkov
Stabilize checking of cfgs at compile-time: `--check-cfg` option This PR stabilize the `--check-cfg` CLI option of `rustc` (and `rustdoc`) 🎉. In particular this PR does two things: 1. it makes the `--check-cfg` option stable 2. and it moves the documentation to the stable books FCP: rust-lang#82450 (comment) Resolves rust-lang#82450 `@rustbot` labels +S-blocked +F-check-cfg r? `@petrochenkov`
2 parents b94a4e6 + a20de73 commit 902487a

File tree

78 files changed

+197
-229
lines changed

Some content is hidden

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

78 files changed

+197
-229
lines changed

compiler/rustc_lint/src/context/diagnostics/check_cfg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ pub(super) fn unexpected_cfg_name(
168168
diag.note("see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration");
169169
} else {
170170
diag.help(format!("to expect this configuration use `--check-cfg={inst}`"));
171-
diag.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration");
171+
diag.note("see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration");
172172
}
173173
}
174174

@@ -272,6 +272,6 @@ pub(super) fn unexpected_cfg_value(
272272
if !is_cfg_a_well_know_name {
273273
diag.help(format!("to expect this configuration use `--check-cfg={inst}`"));
274274
}
275-
diag.note("see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration");
275+
diag.note("see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration");
276276
}
277277
}

compiler/rustc_session/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
13731373
opt::flag_s("h", "help", "Display this message"),
13741374
opt::multi_s("", "cfg", "Configure the compilation environment.
13751375
SPEC supports the syntax `NAME[=\"VALUE\"]`.", "SPEC"),
1376-
opt::multi("", "check-cfg", "Provide list of valid cfg options for checking", "SPEC"),
1376+
opt::multi_s("", "check-cfg", "Provide list of expected cfgs for checking", "SPEC"),
13771377
opt::multi_s(
13781378
"L",
13791379
"",

compiler/rustc_session/src/config/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl CheckCfg {
257257
// `tests/ui/check-cfg/well-known-values.rs` (in order to test the
258258
// expected values of the new config) and bless the all directory.
259259
//
260-
// Don't forget to update `src/doc/unstable-book/src/compiler-flags/check-cfg.md`
260+
// Don't forget to update `src/doc/rustc/src/check-cfg.md`
261261
// in the unstable book as well!
262262

263263
ins!(sym::debug_assertions, no_values);

src/doc/rustc/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
- [Profile-guided Optimization](profile-guided-optimization.md)
7878
- [Instrumentation-based Code Coverage](instrument-coverage.md)
7979
- [Linker-plugin-based LTO](linker-plugin-lto.md)
80+
- [Checking conditional configurations](check-cfg.md)
8081
- [Exploit Mitigations](exploit-mitigations.md)
8182
- [Symbol Mangling](symbol-mangling/index.md)
8283
- [v0 Symbol Format](symbol-mangling/v0.md)

src/doc/unstable-book/src/compiler-flags/check-cfg.md renamed to src/doc/rustc/src/check-cfg.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
# `check-cfg`
2-
3-
The tracking issue for this feature is: [#82450](https://github.com/rust-lang/rust/issues/82450).
4-
5-
------------------------
6-
7-
This feature enables checking of conditional configuration.
1+
# Checking conditional configurations
82

93
`rustc` accepts the `--check-cfg` option, which specifies whether to check conditions and how to
104
check them. The `--check-cfg` option takes a value, called the _check cfg specification_.

src/doc/rustc/src/command-line-arguments.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ The value can either be a single identifier or two identifiers separated by `=`.
1818
For examples, `--cfg 'verbose'` or `--cfg 'feature="serde"'`. These correspond
1919
to `#[cfg(verbose)]` and `#[cfg(feature = "serde")]` respectively.
2020

21+
<a id="option-check-cfg"></a>
22+
## `--check-cfg`: enables checking conditional configurations
23+
24+
This flag will enable checking conditional configurations.
25+
Refer to the [Checking conditional configurations](check-cfg.md) of this book
26+
for further details and explanation.
27+
28+
For examples, `--check-cfg 'cfg(verbose)'` or `--check-cfg 'cfg(feature, values("serde"))'`.
29+
These correspond to `#[cfg(verbose)]` and `#[cfg(feature = "serde")]` respectively.
30+
2131
<a id="option-l-search-path"></a>
2232
## `-L`: add a directory to the library search path
2333

src/doc/rustdoc/src/command-line-arguments.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ This flag accepts the same values as `rustc --cfg`, and uses it to configure
131131
compilation. The example above uses `feature`, but any of the `cfg` values
132132
are acceptable.
133133

134+
## `--check-cfg`: check configuration flags
135+
136+
This flag accepts the same values as `rustc --check-cfg`, and uses it to
137+
check configuration flags.
138+
139+
Using this flag looks like this:
140+
141+
```bash
142+
$ rustdoc src/lib.rs --check-cfg='cfg(my_cfg, values("foo", "bar"))'
143+
```
144+
145+
The example above check every well known names and values (`target_os`, `doc`, `test`, ...)
146+
and check the values of `my_cfg`: `foo` and `bar`.
147+
134148
## `--extern`: specify a dependency's location
135149

136150
Using this flag looks like this:

src/doc/rustdoc/src/unstable-features.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -618,22 +618,6 @@ crate being documented (`foobar`) and a path to output the calls
618618
To scrape examples from test code, e.g. functions marked `#[test]`, then
619619
add the `--scrape-tests` flag.
620620

621-
### `--check-cfg`: check configuration flags
622-
623-
* Tracking issue: [#82450](https://github.com/rust-lang/rust/issues/82450)
624-
625-
This flag accepts the same values as `rustc --check-cfg`, and uses it to check configuration flags.
626-
627-
Using this flag looks like this:
628-
629-
```bash
630-
$ rustdoc src/lib.rs -Z unstable-options \
631-
--check-cfg='cfg(feature, values("foo", "bar"))'
632-
```
633-
634-
The example above check every well known names and values (`target_os`, `doc`, `test`, ...)
635-
and check the values of `feature`: `foo` and `bar`.
636-
637621
### `--generate-link-to-definition`: Generate links on types in source code
638622

639623
* Tracking issue: [#89095](https://github.com/rust-lang/rust/issues/89095)

src/librustdoc/doctest.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,8 @@ pub(crate) fn generate_args_file(file_path: &Path, options: &RustdocOptions) ->
6060
for cfg in &options.cfgs {
6161
content.push(format!("--cfg={cfg}"));
6262
}
63-
if !options.check_cfgs.is_empty() {
64-
content.push("-Zunstable-options".to_string());
65-
for check_cfg in &options.check_cfgs {
66-
content.push(format!("--check-cfg={check_cfg}"));
67-
}
63+
for check_cfg in &options.check_cfgs {
64+
content.push(format!("--check-cfg={check_cfg}"));
6865
}
6966

7067
for lib_str in &options.lib_strs {

src/librustdoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ fn opts() -> Vec<RustcOptGroup> {
242242
o.optmulti("L", "library-path", "directory to add to crate search path", "DIR")
243243
}),
244244
stable("cfg", |o| o.optmulti("", "cfg", "pass a --cfg to rustc", "")),
245-
unstable("check-cfg", |o| o.optmulti("", "check-cfg", "pass a --check-cfg to rustc", "")),
245+
stable("check-cfg", |o| o.optmulti("", "check-cfg", "pass a --check-cfg to rustc", "")),
246246
stable("extern", |o| o.optmulti("", "extern", "pass an --extern to rustc", "NAME[=PATH]")),
247247
unstable("extern-html-root-url", |o| {
248248
o.optmulti(

0 commit comments

Comments
 (0)