Skip to content

Commit 909fcfc

Browse files
committed
Stabilize checking of cfgs at compile-time: --check-cfg option
1 parent 99d0186 commit 909fcfc

Some content is hidden

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

55 files changed

+60
-95
lines changed

compiler/rustc_session/src/config.rs

+1-1
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
"",

src/librustdoc/doctest.rs

+2-5
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

+1-1
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(

tests/rustdoc-ui/check-cfg/check-cfg.rs renamed to tests/rustdoc-ui/check-cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ check-pass
2-
//@ compile-flags: --check-cfg=cfg() -Z unstable-options
2+
//@ compile-flags: --check-cfg=cfg()
33

44
/// uniz is nor a builtin nor pass as arguments so is unexpected
55
#[cfg(uniz)]

tests/rustdoc-ui/check-cfg/check-cfg-test.stderr

-11
This file was deleted.

tests/rustdoc-ui/check-cfg/check-cfg-unstable.rs

-2
This file was deleted.

tests/rustdoc-ui/check-cfg/check-cfg-unstable.stderr

-2
This file was deleted.

tests/ui/check-cfg/allow-at-crate-level.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This test check that #![allow(unexpected_cfgs)] works with --cfg
22
//
33
//@ check-pass
4-
//@ compile-flags: --cfg=unexpected --check-cfg=cfg() -Z unstable-options
4+
//@ compile-flags: --cfg=unexpected --check-cfg=cfg()
55

66
#![allow(unexpected_cfgs)]
77

tests/ui/check-cfg/allow-macro-cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This test check that local #[allow(unexpected_cfgs)] works
22
//
33
//@ check-pass
4-
//@ compile-flags: --check-cfg=cfg() -Z unstable-options
4+
//@ compile-flags: --check-cfg=cfg()
55

66
#[allow(unexpected_cfgs)]
77
fn foo() {

tests/ui/check-cfg/allow-same-level.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This test check that #[allow(unexpected_cfgs)] doesn't work if put on the same level
22
//
33
//@ check-pass
4-
//@ compile-flags: --check-cfg=cfg() -Z unstable-options
4+
//@ compile-flags: --check-cfg=cfg()
55

66
#[allow(unexpected_cfgs)]
77
#[cfg(FALSE)]

tests/ui/check-cfg/allow-top-level.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This test check that a top-level #![allow(unexpected_cfgs)] works
22
//
33
//@ check-pass
4-
//@ compile-flags: --check-cfg=cfg() -Z unstable-options
4+
//@ compile-flags: --check-cfg=cfg()
55

66
#![allow(unexpected_cfgs)]
77

tests/ui/check-cfg/allow-upper-level.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This test check that #[allow(unexpected_cfgs)] work if put on an upper level
22
//
33
//@ check-pass
4-
//@ compile-flags: --check-cfg=cfg() -Z unstable-options
4+
//@ compile-flags: --check-cfg=cfg()
55

66
#[allow(unexpected_cfgs)]
77
mod aa {

tests/ui/check-cfg/cargo-feature.none.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unexpected `cfg` condition value: `serde`
2-
--> $DIR/cargo-feature.rs:14:7
2+
--> $DIR/cargo-feature.rs:13:7
33
|
44
LL | #[cfg(feature = "serde")]
55
| ^^^^^^^^^^^^^^^^^ help: remove the condition
@@ -10,7 +10,7 @@ LL | #[cfg(feature = "serde")]
1010
= note: `#[warn(unexpected_cfgs)]` on by default
1111

1212
warning: unexpected `cfg` condition value: (none)
13-
--> $DIR/cargo-feature.rs:18:7
13+
--> $DIR/cargo-feature.rs:17:7
1414
|
1515
LL | #[cfg(feature)]
1616
| ^^^^^^^ help: remove the condition
@@ -20,7 +20,7 @@ LL | #[cfg(feature)]
2020
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration
2121

2222
warning: unexpected `cfg` condition name: `tokio_unstable`
23-
--> $DIR/cargo-feature.rs:22:7
23+
--> $DIR/cargo-feature.rs:21:7
2424
|
2525
LL | #[cfg(tokio_unstable)]
2626
| ^^^^^^^^^^^^^^
@@ -30,7 +30,7 @@ LL | #[cfg(tokio_unstable)]
3030
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration
3131

3232
warning: unexpected `cfg` condition name: `CONFIG_NVME`
33-
--> $DIR/cargo-feature.rs:26:7
33+
--> $DIR/cargo-feature.rs:25:7
3434
|
3535
LL | #[cfg(CONFIG_NVME = "m")]
3636
| ^^^^^^^^^^^^^^^^^

tests/ui/check-cfg/cargo-feature.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//@ check-pass
66
//@ revisions: some none
77
//@ rustc-env:CARGO_CRATE_NAME=foo
8-
//@ compile-flags: -Z unstable-options
98
//@ [none]compile-flags: --check-cfg=cfg(feature,values())
109
//@ [some]compile-flags: --check-cfg=cfg(feature,values("bitcode"))
1110
//@ [some]compile-flags: --check-cfg=cfg(CONFIG_NVME,values("y"))

tests/ui/check-cfg/cargo-feature.some.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unexpected `cfg` condition value: `serde`
2-
--> $DIR/cargo-feature.rs:14:7
2+
--> $DIR/cargo-feature.rs:13:7
33
|
44
LL | #[cfg(feature = "serde")]
55
| ^^^^^^^^^^^^^^^^^
@@ -10,7 +10,7 @@ LL | #[cfg(feature = "serde")]
1010
= note: `#[warn(unexpected_cfgs)]` on by default
1111

1212
warning: unexpected `cfg` condition value: (none)
13-
--> $DIR/cargo-feature.rs:18:7
13+
--> $DIR/cargo-feature.rs:17:7
1414
|
1515
LL | #[cfg(feature)]
1616
| ^^^^^^^- help: specify a config value: `= "bitcode"`
@@ -20,7 +20,7 @@ LL | #[cfg(feature)]
2020
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration
2121

2222
warning: unexpected `cfg` condition name: `tokio_unstable`
23-
--> $DIR/cargo-feature.rs:22:7
23+
--> $DIR/cargo-feature.rs:21:7
2424
|
2525
LL | #[cfg(tokio_unstable)]
2626
| ^^^^^^^^^^^^^^
@@ -30,7 +30,7 @@ LL | #[cfg(tokio_unstable)]
3030
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration
3131

3232
warning: unexpected `cfg` condition value: `m`
33-
--> $DIR/cargo-feature.rs:26:7
33+
--> $DIR/cargo-feature.rs:25:7
3434
|
3535
LL | #[cfg(CONFIG_NVME = "m")]
3636
| ^^^^^^^^^^^^^^---

tests/ui/check-cfg/cfg-value-for-cfg-name-duplicate.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// This test checks we won't suggest more than 3 span suggestions for cfg names
33
//
44
//@ check-pass
5-
//@ compile-flags: -Z unstable-options
65
//@ compile-flags: --check-cfg=cfg(foo,values("value")) --check-cfg=cfg(bar,values("value")) --check-cfg=cfg(bee,values("value")) --check-cfg=cfg(cow,values("value"))
76

87
#[cfg(value)]

tests/ui/check-cfg/cfg-value-for-cfg-name-duplicate.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unexpected `cfg` condition name: `value`
2-
--> $DIR/cfg-value-for-cfg-name-duplicate.rs:8:7
2+
--> $DIR/cfg-value-for-cfg-name-duplicate.rs:7:7
33
|
44
LL | #[cfg(value)]
55
| ^^^^^

tests/ui/check-cfg/cfg-value-for-cfg-name-multiple.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// This test checks that when a single cfg has a value for user's specified name
33
//
44
//@ check-pass
5-
//@ compile-flags: -Z unstable-options
65
//@ compile-flags: --check-cfg=cfg(foo,values("my_value")) --check-cfg=cfg(bar,values("my_value"))
76

87
#[cfg(my_value)]

tests/ui/check-cfg/cfg-value-for-cfg-name-multiple.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unexpected `cfg` condition name: `my_value`
2-
--> $DIR/cfg-value-for-cfg-name-multiple.rs:8:7
2+
--> $DIR/cfg-value-for-cfg-name-multiple.rs:7:7
33
|
44
LL | #[cfg(my_value)]
55
| ^^^^^^^^

tests/ui/check-cfg/cfg-value-for-cfg-name.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// suggest to use `#[cfg(target_os = "linux")]` instead of `#[cfg(linux)]`
44
//
55
//@ check-pass
6-
//@ compile-flags: -Z unstable-options
76
//@ compile-flags: --check-cfg=cfg()
87

98
#[cfg(linux)]

tests/ui/check-cfg/cfg-value-for-cfg-name.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unexpected `cfg` condition name: `linux`
2-
--> $DIR/cfg-value-for-cfg-name.rs:9:7
2+
--> $DIR/cfg-value-for-cfg-name.rs:8:7
33
|
44
LL | #[cfg(linux)]
55
| ^^^^^ help: found config with similar value: `target_os = "linux"`
@@ -10,7 +10,7 @@ LL | #[cfg(linux)]
1010
= note: `#[warn(unexpected_cfgs)]` on by default
1111

1212
warning: unexpected `cfg` condition name: `linux`
13-
--> $DIR/cfg-value-for-cfg-name.rs:14:7
13+
--> $DIR/cfg-value-for-cfg-name.rs:13:7
1414
|
1515
LL | #[cfg(linux = "os-name")]
1616
| ^^^^^^^^^^^^^^^^^

tests/ui/check-cfg/compact-names.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This test check that we correctly emit an warning for compact cfg
22
//
33
//@ check-pass
4-
//@ compile-flags: --check-cfg=cfg() -Z unstable-options
4+
//@ compile-flags: --check-cfg=cfg()
55

66
#![feature(cfg_target_compact)]
77

tests/ui/check-cfg/compact-values.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This test check that we correctly emit an warning for compact cfg
22
//
33
//@ check-pass
4-
//@ compile-flags: --check-cfg=cfg() -Z unstable-options
4+
//@ compile-flags: --check-cfg=cfg()
55

66
#![feature(cfg_target_compact)]
77

tests/ui/check-cfg/concat-values.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ check-pass
2-
//@ compile-flags: -Z unstable-options
32
//@ compile-flags: --check-cfg=cfg(my_cfg,values("foo")) --check-cfg=cfg(my_cfg,values("bar"))
43
//@ compile-flags: --check-cfg=cfg(my_cfg,values())
54

tests/ui/check-cfg/concat-values.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unexpected `cfg` condition value: (none)
2-
--> $DIR/concat-values.rs:6:7
2+
--> $DIR/concat-values.rs:5:7
33
|
44
LL | #[cfg(my_cfg)]
55
| ^^^^^^
@@ -10,7 +10,7 @@ LL | #[cfg(my_cfg)]
1010
= note: `#[warn(unexpected_cfgs)]` on by default
1111

1212
warning: unexpected `cfg` condition value: `unk`
13-
--> $DIR/concat-values.rs:10:7
13+
--> $DIR/concat-values.rs:9:7
1414
|
1515
LL | #[cfg(my_cfg = "unk")]
1616
| ^^^^^^^^^^^^^^

tests/ui/check-cfg/diagnotics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//@ revisions: cargo rustc
33
//@ [rustc]unset-rustc-env:CARGO_CRATE_NAME
44
//@ [cargo]rustc-env:CARGO_CRATE_NAME=foo
5-
//@ compile-flags: --check-cfg=cfg(feature,values("foo")) --check-cfg=cfg(no_values) -Z unstable-options
5+
//@ compile-flags: --check-cfg=cfg(feature,values("foo")) --check-cfg=cfg(no_values)
66

77
#[cfg(featur)]
88
//~^ WARNING unexpected `cfg` condition name

tests/ui/check-cfg/empty-values.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Check that we detect unexpected value when none are allowed
22
//
33
//@ check-pass
4-
//@ compile-flags: --check-cfg=cfg(foo,values()) -Zunstable-options
4+
//@ compile-flags: --check-cfg=cfg(foo,values())
55

66
#[cfg(foo = "foo")]
77
//~^ WARNING unexpected `cfg` condition value

tests/ui/check-cfg/exhaustive-names-values.empty_cfg.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unexpected `cfg` condition name: `unknown_key`
2-
--> $DIR/exhaustive-names-values.rs:10:7
2+
--> $DIR/exhaustive-names-values.rs:9:7
33
|
44
LL | #[cfg(unknown_key = "value")]
55
| ^^^^^^^^^^^^^^^^^^^^^
@@ -10,7 +10,7 @@ LL | #[cfg(unknown_key = "value")]
1010
= note: `#[warn(unexpected_cfgs)]` on by default
1111

1212
warning: unexpected `cfg` condition value: `value`
13-
--> $DIR/exhaustive-names-values.rs:14:7
13+
--> $DIR/exhaustive-names-values.rs:13:7
1414
|
1515
LL | #[cfg(test = "value")]
1616
| ^^^^----------
@@ -21,7 +21,7 @@ LL | #[cfg(test = "value")]
2121
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
2222

2323
warning: unexpected `cfg` condition name: `feature`
24-
--> $DIR/exhaustive-names-values.rs:18:7
24+
--> $DIR/exhaustive-names-values.rs:17:7
2525
|
2626
LL | #[cfg(feature = "unk")]
2727
| ^^^^^^^^^^^^^^^
@@ -30,7 +30,7 @@ LL | #[cfg(feature = "unk")]
3030
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
3131

3232
warning: unexpected `cfg` condition name: `feature`
33-
--> $DIR/exhaustive-names-values.rs:25:7
33+
--> $DIR/exhaustive-names-values.rs:24:7
3434
|
3535
LL | #[cfg(feature = "std")]
3636
| ^^^^^^^^^^^^^^^

tests/ui/check-cfg/exhaustive-names-values.feature.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unexpected `cfg` condition name: `unknown_key`
2-
--> $DIR/exhaustive-names-values.rs:10:7
2+
--> $DIR/exhaustive-names-values.rs:9:7
33
|
44
LL | #[cfg(unknown_key = "value")]
55
| ^^^^^^^^^^^^^^^^^^^^^
@@ -10,7 +10,7 @@ LL | #[cfg(unknown_key = "value")]
1010
= note: `#[warn(unexpected_cfgs)]` on by default
1111

1212
warning: unexpected `cfg` condition value: `value`
13-
--> $DIR/exhaustive-names-values.rs:14:7
13+
--> $DIR/exhaustive-names-values.rs:13:7
1414
|
1515
LL | #[cfg(test = "value")]
1616
| ^^^^----------
@@ -21,7 +21,7 @@ LL | #[cfg(test = "value")]
2121
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
2222

2323
warning: unexpected `cfg` condition value: `unk`
24-
--> $DIR/exhaustive-names-values.rs:18:7
24+
--> $DIR/exhaustive-names-values.rs:17:7
2525
|
2626
LL | #[cfg(feature = "unk")]
2727
| ^^^^^^^^^^^^^^^

tests/ui/check-cfg/exhaustive-names-values.full.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unexpected `cfg` condition name: `unknown_key`
2-
--> $DIR/exhaustive-names-values.rs:10:7
2+
--> $DIR/exhaustive-names-values.rs:9:7
33
|
44
LL | #[cfg(unknown_key = "value")]
55
| ^^^^^^^^^^^^^^^^^^^^^
@@ -10,7 +10,7 @@ LL | #[cfg(unknown_key = "value")]
1010
= note: `#[warn(unexpected_cfgs)]` on by default
1111

1212
warning: unexpected `cfg` condition value: `value`
13-
--> $DIR/exhaustive-names-values.rs:14:7
13+
--> $DIR/exhaustive-names-values.rs:13:7
1414
|
1515
LL | #[cfg(test = "value")]
1616
| ^^^^----------
@@ -21,7 +21,7 @@ LL | #[cfg(test = "value")]
2121
= note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
2222

2323
warning: unexpected `cfg` condition value: `unk`
24-
--> $DIR/exhaustive-names-values.rs:18:7
24+
--> $DIR/exhaustive-names-values.rs:17:7
2525
|
2626
LL | #[cfg(feature = "unk")]
2727
| ^^^^^^^^^^^^^^^

tests/ui/check-cfg/exhaustive-names-values.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//
33
//@ check-pass
44
//@ revisions: empty_cfg feature full
5-
//@ compile-flags: -Z unstable-options
65
//@ [empty_cfg]compile-flags: --check-cfg=cfg()
76
//@ [feature]compile-flags: --check-cfg=cfg(feature,values("std"))
87
//@ [full]compile-flags: --check-cfg=cfg(feature,values("std")) --check-cfg=cfg()

tests/ui/check-cfg/exhaustive-names.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Check warning for unexpected cfg
22
//
33
//@ check-pass
4-
//@ compile-flags: --check-cfg=cfg() -Z unstable-options
4+
//@ compile-flags: --check-cfg=cfg()
55

66
#[cfg(unknown_key = "value")]
77
//~^ WARNING unexpected `cfg` condition name

0 commit comments

Comments
 (0)