Skip to content

Commit f05fa1c

Browse files
committed
Change unexpected_cfg to allow by default
This allows to find solutions to the false positives that were found in the ecosystem before turning it to `warn` by default again. Most projects hit by this seem to just disable the warning, which indicates that it isn't working as expected. CC rust-lang#124800 CC rust-lang#124804 CC rust-lang#124821 CC hyperium/hyper#3660 CC microsoft/windows-rs#3022 CC rust-bitcoin/rust-bitcoin#2748 CC tokio-rs/tokio#6538
1 parent 60a7c19 commit f05fa1c

File tree

59 files changed

+330
-152
lines changed

Some content is hidden

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

59 files changed

+330
-152
lines changed

compiler/rustc_lint_defs/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3345,7 +3345,7 @@ declare_lint! {
33453345
/// The known condition include names or values passed in `--check-cfg`, and some
33463346
/// well-knows names and values built into the compiler.
33473347
pub UNEXPECTED_CFGS,
3348-
Warn,
3348+
Allow,
33493349
"detects unexpected names and values in `#[cfg]` conditions",
33503350
}
33513351

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

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//@ no-auto-check-cfg
55
//@ compile-flags: --check-cfg=cfg()
66

7+
#![warn(unexpected_cfgs)]
8+
79
#[allow(unexpected_cfgs)]
810
fn foo() {
911
if cfg!(FALSE) {}

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

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//@ no-auto-check-cfg
55
//@ compile-flags: --check-cfg=cfg()
66

7+
#![warn(unexpected_cfgs)]
8+
79
#[allow(unexpected_cfgs)]
810
#[cfg(FALSE)]
911
//~^ WARNING unexpected `cfg` condition name
+6-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
warning: unexpected `cfg` condition name: `FALSE`
2-
--> $DIR/allow-same-level.rs:8:7
2+
--> $DIR/allow-same-level.rs:10:7
33
|
44
LL | #[cfg(FALSE)]
55
| ^^^^^
66
|
77
= help: expected names are: `clippy`, `debug_assertions`, `doc`, `doctest`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, `windows`
88
= help: to expect this configuration use `--check-cfg=cfg(FALSE)`
99
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
10-
= note: `#[warn(unexpected_cfgs)]` on by default
10+
note: the lint level is defined here
11+
--> $DIR/allow-same-level.rs:7:9
12+
|
13+
LL | #![warn(unexpected_cfgs)]
14+
| ^^^^^^^^^^^^^^^
1115

1216
warning: 1 warning emitted
1317

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

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//@ no-auto-check-cfg
55
//@ compile-flags: --check-cfg=cfg()
66

7+
#![warn(unexpected_cfgs)]
8+
79
#[allow(unexpected_cfgs)]
810
mod aa {
911
#[cfg(FALSE)]

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
warning: unexpected `cfg` condition value: `serde`
2-
--> $DIR/cargo-feature.rs:14:7
2+
--> $DIR/cargo-feature.rs:16:7
33
|
44
LL | #[cfg(feature = "serde")]
55
| ^^^^^^^^^^^^^^^^^ help: remove the condition
66
|
77
= note: no expected values for `feature`
88
= help: consider adding `serde` as a feature in `Cargo.toml`
99
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
10-
= note: `#[warn(unexpected_cfgs)]` on by default
10+
note: the lint level is defined here
11+
--> $DIR/cargo-feature.rs:14:9
12+
|
13+
LL | #![warn(unexpected_cfgs)]
14+
| ^^^^^^^^^^^^^^^
1115

1216
warning: unexpected `cfg` condition value: (none)
13-
--> $DIR/cargo-feature.rs:18:7
17+
--> $DIR/cargo-feature.rs:20:7
1418
|
1519
LL | #[cfg(feature)]
1620
| ^^^^^^^ help: remove the condition
@@ -20,7 +24,7 @@ LL | #[cfg(feature)]
2024
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
2125

2226
warning: unexpected `cfg` condition name: `tokio_unstable`
23-
--> $DIR/cargo-feature.rs:22:7
27+
--> $DIR/cargo-feature.rs:24:7
2428
|
2529
LL | #[cfg(tokio_unstable)]
2630
| ^^^^^^^^^^^^^^
@@ -30,7 +34,7 @@ LL | #[cfg(tokio_unstable)]
3034
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
3135

3236
warning: unexpected `cfg` condition name: `CONFIG_NVME`
33-
--> $DIR/cargo-feature.rs:26:7
37+
--> $DIR/cargo-feature.rs:28:7
3438
|
3539
LL | #[cfg(CONFIG_NVME = "m")]
3640
| ^^^^^^^^^^^^^^^^^

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

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
//@ [some]compile-flags: --check-cfg=cfg(CONFIG_NVME,values("y"))
1212
//@ [none]error-pattern:Cargo.toml
1313

14+
#![warn(unexpected_cfgs)]
15+
1416
#[cfg(feature = "serde")]
1517
//~^ WARNING unexpected `cfg` condition value
1618
fn ser() {}

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
warning: unexpected `cfg` condition value: `serde`
2-
--> $DIR/cargo-feature.rs:14:7
2+
--> $DIR/cargo-feature.rs:16:7
33
|
44
LL | #[cfg(feature = "serde")]
55
| ^^^^^^^^^^^^^^^^^
66
|
77
= note: expected values for `feature` are: `bitcode`
88
= help: consider adding `serde` as a feature in `Cargo.toml`
99
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
10-
= note: `#[warn(unexpected_cfgs)]` on by default
10+
note: the lint level is defined here
11+
--> $DIR/cargo-feature.rs:14:9
12+
|
13+
LL | #![warn(unexpected_cfgs)]
14+
| ^^^^^^^^^^^^^^^
1115

1216
warning: unexpected `cfg` condition value: (none)
13-
--> $DIR/cargo-feature.rs:18:7
17+
--> $DIR/cargo-feature.rs:20:7
1418
|
1519
LL | #[cfg(feature)]
1620
| ^^^^^^^- help: specify a config value: `= "bitcode"`
@@ -20,7 +24,7 @@ LL | #[cfg(feature)]
2024
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
2125

2226
warning: unexpected `cfg` condition name: `tokio_unstable`
23-
--> $DIR/cargo-feature.rs:22:7
27+
--> $DIR/cargo-feature.rs:24:7
2428
|
2529
LL | #[cfg(tokio_unstable)]
2630
| ^^^^^^^^^^^^^^
@@ -30,7 +34,7 @@ LL | #[cfg(tokio_unstable)]
3034
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
3135

3236
warning: unexpected `cfg` condition value: `m`
33-
--> $DIR/cargo-feature.rs:26:7
37+
--> $DIR/cargo-feature.rs:28:7
3438
|
3539
LL | #[cfg(CONFIG_NVME = "m")]
3640
| ^^^^^^^^^^^^^^---

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

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
//@ no-auto-check-cfg
66
//@ 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"))
77

8+
#![warn(unexpected_cfgs)]
9+
810
#[cfg(value)]
911
//~^ WARNING unexpected `cfg` condition name: `value`
1012
fn x() {}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
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:10:7
33
|
44
LL | #[cfg(value)]
55
| ^^^^^
66
|
77
= help: expected names are: `bar`, `bee`, `clippy`, `cow`, `debug_assertions`, `doc`, `doctest`, `foo`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, `windows`
88
= help: to expect this configuration use `--check-cfg=cfg(value)`
99
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
10-
= note: `#[warn(unexpected_cfgs)]` on by default
10+
note: the lint level is defined here
11+
--> $DIR/cfg-value-for-cfg-name-duplicate.rs:8:9
12+
|
13+
LL | #![warn(unexpected_cfgs)]
14+
| ^^^^^^^^^^^^^^^
1115

1216
warning: 1 warning emitted
1317

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

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
//@ no-auto-check-cfg
66
//@ compile-flags: --check-cfg=cfg(foo,values("my_value")) --check-cfg=cfg(bar,values("my_value"))
77

8+
#![warn(unexpected_cfgs)]
9+
810
#[cfg(my_value)]
911
//~^ WARNING unexpected `cfg` condition name: `my_value`
1012
fn x() {}

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
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:10:7
33
|
44
LL | #[cfg(my_value)]
55
| ^^^^^^^^
66
|
77
= help: expected names are: `bar`, `clippy`, `debug_assertions`, `doc`, `doctest`, `foo`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, `windows`
88
= help: to expect this configuration use `--check-cfg=cfg(my_value)`
99
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
10-
= note: `#[warn(unexpected_cfgs)]` on by default
10+
note: the lint level is defined here
11+
--> $DIR/cfg-value-for-cfg-name-multiple.rs:8:9
12+
|
13+
LL | #![warn(unexpected_cfgs)]
14+
| ^^^^^^^^^^^^^^^
1115
help: found config with similar value
1216
|
1317
LL | #[cfg(foo = "my_value")]

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

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//@ no-auto-check-cfg
77
//@ compile-flags: --check-cfg=cfg()
88

9+
#![warn(unexpected_cfgs)]
10+
911
#[cfg(linux)]
1012
//~^ WARNING unexpected `cfg` condition name: `linux`
1113
fn x() {}

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
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:11:7
33
|
44
LL | #[cfg(linux)]
55
| ^^^^^ help: found config with similar value: `target_os = "linux"`
66
|
77
= help: expected names are: `clippy`, `debug_assertions`, `doc`, `doctest`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, `windows`
88
= help: to expect this configuration use `--check-cfg=cfg(linux)`
99
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
10-
= note: `#[warn(unexpected_cfgs)]` on by default
10+
note: the lint level is defined here
11+
--> $DIR/cfg-value-for-cfg-name.rs:9:9
12+
|
13+
LL | #![warn(unexpected_cfgs)]
14+
| ^^^^^^^^^^^^^^^
1115

1216
warning: unexpected `cfg` condition name: `linux`
13-
--> $DIR/cfg-value-for-cfg-name.rs:14:7
17+
--> $DIR/cfg-value-for-cfg-name.rs:16:7
1418
|
1519
LL | #[cfg(linux = "os-name")]
1620
| ^^^^^^^^^^^^^^^^^

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

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//@ no-auto-check-cfg
55
//@ compile-flags: --check-cfg=cfg()
66

7+
#![warn(unexpected_cfgs)]
8+
79
#![feature(cfg_target_compact)]
810

911
#[cfg(target(os = "linux", arch = "arm"))]
+6-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
warning: unexpected `cfg` condition name: `target_architecture`
2-
--> $DIR/compact-names.rs:12:28
2+
--> $DIR/compact-names.rs:14:28
33
|
44
LL | #[cfg(target(os = "linux", architecture = "arm"))]
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: expected names are: `clippy`, `debug_assertions`, `doc`, `doctest`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, `windows`
88
= help: to expect this configuration use `--check-cfg=cfg(target_architecture, values("arm"))`
99
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
10-
= note: `#[warn(unexpected_cfgs)]` on by default
10+
note: the lint level is defined here
11+
--> $DIR/compact-names.rs:7:9
12+
|
13+
LL | #![warn(unexpected_cfgs)]
14+
| ^^^^^^^^^^^^^^^
1115

1216
warning: 1 warning emitted
1317

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

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//@ no-auto-check-cfg
55
//@ compile-flags: --check-cfg=cfg()
66

7+
#![warn(unexpected_cfgs)]
8+
79
#![feature(cfg_target_compact)]
810

911
#[cfg(target(os = "linux", arch = "arm"))]
+6-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
warning: unexpected `cfg` condition value: `X`
2-
--> $DIR/compact-values.rs:12:28
2+
--> $DIR/compact-values.rs:14:28
33
|
44
LL | #[cfg(target(os = "linux", pointer_width = "X"))]
55
| ^^^^^^^^^^^^^^^^^^^
66
|
77
= note: expected values for `target_pointer_width` are: `16`, `32`, `64`
88
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
9-
= note: `#[warn(unexpected_cfgs)]` on by default
9+
note: the lint level is defined here
10+
--> $DIR/compact-values.rs:7:9
11+
|
12+
LL | #![warn(unexpected_cfgs)]
13+
| ^^^^^^^^^^^^^^^
1014

1115
warning: 1 warning emitted
1216

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

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//@ compile-flags: --check-cfg=cfg(my_cfg,values("foo")) --check-cfg=cfg(my_cfg,values("bar"))
44
//@ compile-flags: --check-cfg=cfg(my_cfg,values())
55

6+
#![warn(unexpected_cfgs)]
7+
68
#[cfg(my_cfg)]
79
//~^ WARNING unexpected `cfg` condition value
810
fn my_cfg() {}

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
warning: unexpected `cfg` condition value: (none)
2-
--> $DIR/concat-values.rs:6:7
2+
--> $DIR/concat-values.rs:8:7
33
|
44
LL | #[cfg(my_cfg)]
55
| ^^^^^^
66
|
77
= note: expected values for `my_cfg` are: `bar`, `foo`
88
= help: to expect this configuration use `--check-cfg=cfg(my_cfg)`
99
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
10-
= note: `#[warn(unexpected_cfgs)]` on by default
10+
note: the lint level is defined here
11+
--> $DIR/concat-values.rs:6:9
12+
|
13+
LL | #![warn(unexpected_cfgs)]
14+
| ^^^^^^^^^^^^^^^
1115

1216
warning: unexpected `cfg` condition value: `unk`
13-
--> $DIR/concat-values.rs:10:7
17+
--> $DIR/concat-values.rs:12:7
1418
|
1519
LL | #[cfg(my_cfg = "unk")]
1620
| ^^^^^^^^^^^^^^

tests/ui/check-cfg/diagnotics.cargo.stderr

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
warning: unexpected `cfg` condition name: `featur`
2-
--> $DIR/diagnotics.rs:8:7
2+
--> $DIR/diagnotics.rs:10:7
33
|
44
LL | #[cfg(featur)]
55
| ^^^^^^ help: there is a config with a similar name: `feature`
66
|
77
= help: expected values for `feature` are: `foo`
88
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
9-
= note: `#[warn(unexpected_cfgs)]` on by default
9+
note: the lint level is defined here
10+
--> $DIR/diagnotics.rs:8:9
11+
|
12+
LL | #![warn(unexpected_cfgs)]
13+
| ^^^^^^^^^^^^^^^
1014

1115
warning: unexpected `cfg` condition name: `featur`
12-
--> $DIR/diagnotics.rs:12:7
16+
--> $DIR/diagnotics.rs:14:7
1317
|
1418
LL | #[cfg(featur = "foo")]
1519
| ^^^^^^^^^^^^^^
@@ -21,7 +25,7 @@ LL | #[cfg(feature = "foo")]
2125
| ~~~~~~~
2226

2327
warning: unexpected `cfg` condition name: `featur`
24-
--> $DIR/diagnotics.rs:16:7
28+
--> $DIR/diagnotics.rs:18:7
2529
|
2630
LL | #[cfg(featur = "fo")]
2731
| ^^^^^^^^^^^^^
@@ -34,7 +38,7 @@ LL | #[cfg(feature = "foo")]
3438
| ~~~~~~~~~~~~~~~
3539

3640
warning: unexpected `cfg` condition name: `no_value`
37-
--> $DIR/diagnotics.rs:23:7
41+
--> $DIR/diagnotics.rs:25:7
3842
|
3943
LL | #[cfg(no_value)]
4044
| ^^^^^^^^ help: there is a config with a similar name: `no_values`
@@ -43,7 +47,7 @@ LL | #[cfg(no_value)]
4347
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
4448

4549
warning: unexpected `cfg` condition name: `no_value`
46-
--> $DIR/diagnotics.rs:27:7
50+
--> $DIR/diagnotics.rs:29:7
4751
|
4852
LL | #[cfg(no_value = "foo")]
4953
| ^^^^^^^^^^^^^^^^
@@ -56,7 +60,7 @@ LL | #[cfg(no_values)]
5660
| ~~~~~~~~~
5761

5862
warning: unexpected `cfg` condition value: `bar`
59-
--> $DIR/diagnotics.rs:31:7
63+
--> $DIR/diagnotics.rs:33:7
6064
|
6165
LL | #[cfg(no_values = "bar")]
6266
| ^^^^^^^^^--------

tests/ui/check-cfg/diagnotics.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
//@ [cargo]rustc-env:CARGO_CRATE_NAME=foo
66
//@ compile-flags: --check-cfg=cfg(feature,values("foo")) --check-cfg=cfg(no_values)
77

8+
#![warn(unexpected_cfgs)]
9+
810
#[cfg(featur)]
911
//~^ WARNING unexpected `cfg` condition name
1012
fn feature() {}

0 commit comments

Comments
 (0)