Skip to content

Commit

Permalink
Change unexpected_cfg to allow by default
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tbu- committed May 7, 2024
1 parent 60a7c19 commit f05fa1c
Show file tree
Hide file tree
Showing 59 changed files with 330 additions and 152 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3345,7 +3345,7 @@ declare_lint! {
/// The known condition include names or values passed in `--check-cfg`, and some
/// well-knows names and values built into the compiler.
pub UNEXPECTED_CFGS,
Warn,
Allow,
"detects unexpected names and values in `#[cfg]` conditions",
}

Expand Down
2 changes: 2 additions & 0 deletions tests/ui/check-cfg/allow-macro-cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//@ no-auto-check-cfg
//@ compile-flags: --check-cfg=cfg()

#![warn(unexpected_cfgs)]

#[allow(unexpected_cfgs)]
fn foo() {
if cfg!(FALSE) {}
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/check-cfg/allow-same-level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//@ no-auto-check-cfg
//@ compile-flags: --check-cfg=cfg()

#![warn(unexpected_cfgs)]

#[allow(unexpected_cfgs)]
#[cfg(FALSE)]
//~^ WARNING unexpected `cfg` condition name
Expand Down
8 changes: 6 additions & 2 deletions tests/ui/check-cfg/allow-same-level.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
warning: unexpected `cfg` condition name: `FALSE`
--> $DIR/allow-same-level.rs:8:7
--> $DIR/allow-same-level.rs:10:7
|
LL | #[cfg(FALSE)]
| ^^^^^
|
= 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`
= help: to expect this configuration use `--check-cfg=cfg(FALSE)`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default
note: the lint level is defined here
--> $DIR/allow-same-level.rs:7:9
|
LL | #![warn(unexpected_cfgs)]
| ^^^^^^^^^^^^^^^

warning: 1 warning emitted

2 changes: 2 additions & 0 deletions tests/ui/check-cfg/allow-upper-level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//@ no-auto-check-cfg
//@ compile-flags: --check-cfg=cfg()

#![warn(unexpected_cfgs)]

#[allow(unexpected_cfgs)]
mod aa {
#[cfg(FALSE)]
Expand Down
14 changes: 9 additions & 5 deletions tests/ui/check-cfg/cargo-feature.none.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
warning: unexpected `cfg` condition value: `serde`
--> $DIR/cargo-feature.rs:14:7
--> $DIR/cargo-feature.rs:16:7
|
LL | #[cfg(feature = "serde")]
| ^^^^^^^^^^^^^^^^^ help: remove the condition
|
= note: no expected values for `feature`
= help: consider adding `serde` as a feature in `Cargo.toml`
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default
note: the lint level is defined here
--> $DIR/cargo-feature.rs:14:9
|
LL | #![warn(unexpected_cfgs)]
| ^^^^^^^^^^^^^^^

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

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

warning: unexpected `cfg` condition name: `CONFIG_NVME`
--> $DIR/cargo-feature.rs:26:7
--> $DIR/cargo-feature.rs:28:7
|
LL | #[cfg(CONFIG_NVME = "m")]
| ^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/check-cfg/cargo-feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
//@ [some]compile-flags: --check-cfg=cfg(CONFIG_NVME,values("y"))
//@ [none]error-pattern:Cargo.toml

#![warn(unexpected_cfgs)]

#[cfg(feature = "serde")]
//~^ WARNING unexpected `cfg` condition value
fn ser() {}
Expand Down
14 changes: 9 additions & 5 deletions tests/ui/check-cfg/cargo-feature.some.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
warning: unexpected `cfg` condition value: `serde`
--> $DIR/cargo-feature.rs:14:7
--> $DIR/cargo-feature.rs:16:7
|
LL | #[cfg(feature = "serde")]
| ^^^^^^^^^^^^^^^^^
|
= note: expected values for `feature` are: `bitcode`
= help: consider adding `serde` as a feature in `Cargo.toml`
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default
note: the lint level is defined here
--> $DIR/cargo-feature.rs:14:9
|
LL | #![warn(unexpected_cfgs)]
| ^^^^^^^^^^^^^^^

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

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

warning: unexpected `cfg` condition value: `m`
--> $DIR/cargo-feature.rs:26:7
--> $DIR/cargo-feature.rs:28:7
|
LL | #[cfg(CONFIG_NVME = "m")]
| ^^^^^^^^^^^^^^---
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/check-cfg/cfg-value-for-cfg-name-duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//@ no-auto-check-cfg
//@ 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"))

#![warn(unexpected_cfgs)]

#[cfg(value)]
//~^ WARNING unexpected `cfg` condition name: `value`
fn x() {}
Expand Down
8 changes: 6 additions & 2 deletions tests/ui/check-cfg/cfg-value-for-cfg-name-duplicate.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
warning: unexpected `cfg` condition name: `value`
--> $DIR/cfg-value-for-cfg-name-duplicate.rs:8:7
--> $DIR/cfg-value-for-cfg-name-duplicate.rs:10:7
|
LL | #[cfg(value)]
| ^^^^^
|
= 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`
= help: to expect this configuration use `--check-cfg=cfg(value)`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default
note: the lint level is defined here
--> $DIR/cfg-value-for-cfg-name-duplicate.rs:8:9
|
LL | #![warn(unexpected_cfgs)]
| ^^^^^^^^^^^^^^^

warning: 1 warning emitted

2 changes: 2 additions & 0 deletions tests/ui/check-cfg/cfg-value-for-cfg-name-multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//@ no-auto-check-cfg
//@ compile-flags: --check-cfg=cfg(foo,values("my_value")) --check-cfg=cfg(bar,values("my_value"))

#![warn(unexpected_cfgs)]

#[cfg(my_value)]
//~^ WARNING unexpected `cfg` condition name: `my_value`
fn x() {}
Expand Down
8 changes: 6 additions & 2 deletions tests/ui/check-cfg/cfg-value-for-cfg-name-multiple.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
warning: unexpected `cfg` condition name: `my_value`
--> $DIR/cfg-value-for-cfg-name-multiple.rs:8:7
--> $DIR/cfg-value-for-cfg-name-multiple.rs:10:7
|
LL | #[cfg(my_value)]
| ^^^^^^^^
|
= 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`
= help: to expect this configuration use `--check-cfg=cfg(my_value)`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default
note: the lint level is defined here
--> $DIR/cfg-value-for-cfg-name-multiple.rs:8:9
|
LL | #![warn(unexpected_cfgs)]
| ^^^^^^^^^^^^^^^
help: found config with similar value
|
LL | #[cfg(foo = "my_value")]
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/check-cfg/cfg-value-for-cfg-name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//@ no-auto-check-cfg
//@ compile-flags: --check-cfg=cfg()

#![warn(unexpected_cfgs)]

#[cfg(linux)]
//~^ WARNING unexpected `cfg` condition name: `linux`
fn x() {}
Expand Down
10 changes: 7 additions & 3 deletions tests/ui/check-cfg/cfg-value-for-cfg-name.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
warning: unexpected `cfg` condition name: `linux`
--> $DIR/cfg-value-for-cfg-name.rs:9:7
--> $DIR/cfg-value-for-cfg-name.rs:11:7
|
LL | #[cfg(linux)]
| ^^^^^ help: found config with similar value: `target_os = "linux"`
|
= 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`
= help: to expect this configuration use `--check-cfg=cfg(linux)`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default
note: the lint level is defined here
--> $DIR/cfg-value-for-cfg-name.rs:9:9
|
LL | #![warn(unexpected_cfgs)]
| ^^^^^^^^^^^^^^^

warning: unexpected `cfg` condition name: `linux`
--> $DIR/cfg-value-for-cfg-name.rs:14:7
--> $DIR/cfg-value-for-cfg-name.rs:16:7
|
LL | #[cfg(linux = "os-name")]
| ^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/check-cfg/compact-names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//@ no-auto-check-cfg
//@ compile-flags: --check-cfg=cfg()

#![warn(unexpected_cfgs)]

#![feature(cfg_target_compact)]

#[cfg(target(os = "linux", arch = "arm"))]
Expand Down
8 changes: 6 additions & 2 deletions tests/ui/check-cfg/compact-names.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
warning: unexpected `cfg` condition name: `target_architecture`
--> $DIR/compact-names.rs:12:28
--> $DIR/compact-names.rs:14:28
|
LL | #[cfg(target(os = "linux", architecture = "arm"))]
| ^^^^^^^^^^^^^^^^^^^^
|
= 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`
= help: to expect this configuration use `--check-cfg=cfg(target_architecture, values("arm"))`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default
note: the lint level is defined here
--> $DIR/compact-names.rs:7:9
|
LL | #![warn(unexpected_cfgs)]
| ^^^^^^^^^^^^^^^

warning: 1 warning emitted

2 changes: 2 additions & 0 deletions tests/ui/check-cfg/compact-values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//@ no-auto-check-cfg
//@ compile-flags: --check-cfg=cfg()

#![warn(unexpected_cfgs)]

#![feature(cfg_target_compact)]

#[cfg(target(os = "linux", arch = "arm"))]
Expand Down
8 changes: 6 additions & 2 deletions tests/ui/check-cfg/compact-values.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
warning: unexpected `cfg` condition value: `X`
--> $DIR/compact-values.rs:12:28
--> $DIR/compact-values.rs:14:28
|
LL | #[cfg(target(os = "linux", pointer_width = "X"))]
| ^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `target_pointer_width` are: `16`, `32`, `64`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default
note: the lint level is defined here
--> $DIR/compact-values.rs:7:9
|
LL | #![warn(unexpected_cfgs)]
| ^^^^^^^^^^^^^^^

warning: 1 warning emitted

2 changes: 2 additions & 0 deletions tests/ui/check-cfg/concat-values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//@ compile-flags: --check-cfg=cfg(my_cfg,values("foo")) --check-cfg=cfg(my_cfg,values("bar"))
//@ compile-flags: --check-cfg=cfg(my_cfg,values())

#![warn(unexpected_cfgs)]

#[cfg(my_cfg)]
//~^ WARNING unexpected `cfg` condition value
fn my_cfg() {}
Expand Down
10 changes: 7 additions & 3 deletions tests/ui/check-cfg/concat-values.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
warning: unexpected `cfg` condition value: (none)
--> $DIR/concat-values.rs:6:7
--> $DIR/concat-values.rs:8:7
|
LL | #[cfg(my_cfg)]
| ^^^^^^
|
= note: expected values for `my_cfg` are: `bar`, `foo`
= help: to expect this configuration use `--check-cfg=cfg(my_cfg)`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default
note: the lint level is defined here
--> $DIR/concat-values.rs:6:9
|
LL | #![warn(unexpected_cfgs)]
| ^^^^^^^^^^^^^^^

warning: unexpected `cfg` condition value: `unk`
--> $DIR/concat-values.rs:10:7
--> $DIR/concat-values.rs:12:7
|
LL | #[cfg(my_cfg = "unk")]
| ^^^^^^^^^^^^^^
Expand Down
18 changes: 11 additions & 7 deletions tests/ui/check-cfg/diagnotics.cargo.stderr
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
warning: unexpected `cfg` condition name: `featur`
--> $DIR/diagnotics.rs:8:7
--> $DIR/diagnotics.rs:10:7
|
LL | #[cfg(featur)]
| ^^^^^^ help: there is a config with a similar name: `feature`
|
= help: expected values for `feature` are: `foo`
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default
note: the lint level is defined here
--> $DIR/diagnotics.rs:8:9
|
LL | #![warn(unexpected_cfgs)]
| ^^^^^^^^^^^^^^^

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

warning: unexpected `cfg` condition name: `featur`
--> $DIR/diagnotics.rs:16:7
--> $DIR/diagnotics.rs:18:7
|
LL | #[cfg(featur = "fo")]
| ^^^^^^^^^^^^^
Expand All @@ -34,7 +38,7 @@ LL | #[cfg(feature = "foo")]
| ~~~~~~~~~~~~~~~

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

warning: unexpected `cfg` condition name: `no_value`
--> $DIR/diagnotics.rs:27:7
--> $DIR/diagnotics.rs:29:7
|
LL | #[cfg(no_value = "foo")]
| ^^^^^^^^^^^^^^^^
Expand All @@ -56,7 +60,7 @@ LL | #[cfg(no_values)]
| ~~~~~~~~~

warning: unexpected `cfg` condition value: `bar`
--> $DIR/diagnotics.rs:31:7
--> $DIR/diagnotics.rs:33:7
|
LL | #[cfg(no_values = "bar")]
| ^^^^^^^^^--------
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/check-cfg/diagnotics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//@ [cargo]rustc-env:CARGO_CRATE_NAME=foo
//@ compile-flags: --check-cfg=cfg(feature,values("foo")) --check-cfg=cfg(no_values)

#![warn(unexpected_cfgs)]

#[cfg(featur)]
//~^ WARNING unexpected `cfg` condition name
fn feature() {}
Expand Down
Loading

0 comments on commit f05fa1c

Please sign in to comment.