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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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
Lines changed: 6 additions & 2 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 9 additions & 5 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 9 additions & 5 deletions
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

Lines changed: 2 additions & 0 deletions
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() {}
Lines changed: 6 additions & 2 deletions
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

0 commit comments

Comments
 (0)