Auto merge of #100574 - Urgau:check-cfg-warn-cfg, r=petrochenkov

Add warning against unexpected --cfg with --check-cfg

This PR adds a warning when an unexpected `--cfg` is specified but not in the specified list of `--check-cfg`.

This is the follow-up PR I mentioned in https://github.com/rust-lang/rust/pull/99519.

r? `@petrochenkov`
This commit is contained in:
bors 2022-09-03 12:02:14 +00:00
commit 47d1cdb0bc
10 changed files with 70 additions and 8 deletions

View file

@ -0,0 +1,8 @@
// This test check that #![allow(unexpected_cfgs)] works with --cfg
//
// check-pass
// compile-flags: --cfg=unexpected --check-cfg=names() -Z unstable-options
#![allow(unexpected_cfgs)]
fn main() {}

View file

@ -15,5 +15,9 @@ LL | #[cfg(feature = "rand")]
|
= note: expected values for `feature` are: full, serde
warning: 2 warnings emitted
warning: unexpected condition value `rand` for condition name `feature`
|
= help: was set with `--cfg` but isn't in the `--check-cfg` expected values
warning: 3 warnings emitted

View file

@ -3,7 +3,7 @@
// we correctly lint on the `cfg!` macro and `cfg_attr` attribute.
//
// check-pass
// compile-flags: --check-cfg=names() --check-cfg=values(feature,"foo") --cfg feature="bar" -Z unstable-options
// compile-flags: --check-cfg=names() --check-cfg=values(feature,"foo") --cfg feature="bar" --cfg unknown_name -Z unstable-options
#[cfg(windows)]
fn do_windows_stuff() {}

View file

@ -28,6 +28,14 @@ warning: unexpected `cfg` condition name
LL | #[cfg_attr(uu, test)]
| ^^
warning: unexpected condition value `bar` for condition name `feature`
|
= help: was set with `--cfg` but isn't in the `--check-cfg` expected values
warning: unexpected `unknown_name` as condition name
|
= help: was set with `--cfg` but isn't in the `--check-cfg` expected names
warning: unexpected `cfg` condition name
--> $DIR/mix.rs:35:10
|
@ -170,5 +178,5 @@ LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
|
= note: expected values for `feature` are: foo
warning: 25 warnings emitted
warning: 27 warnings emitted