Strengthen well known check-cfg names and values test

This commit is contained in:
Urgau 2023-12-07 12:04:00 +01:00
parent c41669970a
commit bba9862b95
3 changed files with 305 additions and 67 deletions

View File

@ -1422,6 +1422,9 @@ impl CheckCfg {
};
// NOTE: This should be kept in sync with `default_configuration`
//
// When adding a new config here you should also update
// `tests/ui/check-cfg/well-known-values.rs`.
let panic_values = &PanicStrategy::all();

View File

@ -1,41 +1,104 @@
// This test check that we lint on non well known values and that we don't lint on well known
// values
// This test check that we recognize all the well known config names
// and that we correctly lint on unexpected values.
//
// This test also serve as an "anti-regression" for the well known
// values since the suggestion shows them.
//
// check-pass
// compile-flags: --check-cfg=cfg() -Z unstable-options
#[cfg(target_os = "linuz")]
#![feature(cfg_overflow_checks)]
#![feature(cfg_relocation_model)]
#![feature(cfg_sanitize)]
#![feature(cfg_target_abi)]
#![feature(cfg_target_has_atomic)]
#![feature(cfg_target_has_atomic_equal_alignment)]
#![feature(cfg_target_thread_local)]
// This part makes sure that none of the well known names are
// unexpected.
//
// BUT to make sure that no expected values changes without
// being noticed we pass them a obviously wrong value so the
// diagnostic prints the list of expected values.
#[cfg(any(
// tidy-alphabetical-start
debug_assertions = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
doc = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
doctest = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
miri = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
overflow_checks = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
panic = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
proc_macro = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
relocation_model = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
sanitize = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_abi = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_arch = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_endian = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_env = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_family = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_feature = "_UNEXPECTED_VALUE", // currently *any* values are "expected"
target_has_atomic = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_has_atomic_equal_alignment = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_has_atomic_load_store = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_os = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_pointer_width = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_thread_local = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_vendor = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
test = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
unix = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
windows = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
// tidy-alphabetical-end
))]
fn unexpected_values() {}
#[cfg(target_os = "linuz")] // testing that we suggest `linux`
//~^ WARNING unexpected `cfg` condition value
fn target_os_linux_misspell() {}
// The #[cfg]s below serve as a safeguard to make sure we
// don't lint when using an expected well-known name and
// value, only a small subset of all possible expected
// configs are tested, since we already test the names
// above and don't need to test all values, just different
// combinations (without value, with value, both...).
#[cfg(target_os = "linux")]
fn target_os_linux() {}
#[cfg(target_has_atomic = "0")]
//~^ WARNING unexpected `cfg` condition value
fn target_has_atomic_invalid() {}
#[cfg(target_has_atomic = "8")]
fn target_has_atomic() {}
fn target_has_atomic_8() {}
#[cfg(unix = "aa")]
//~^ WARNING unexpected `cfg` condition value
fn unix_with_value() {}
#[cfg(target_has_atomic)]
fn target_has_atomic() {}
#[cfg(unix)]
fn unix() {}
#[cfg(miri = "miri")]
//~^ WARNING unexpected `cfg` condition value
fn miri_with_value() {}
#[cfg(miri)]
fn miri() {}
#[cfg(doc = "linux")]
//~^ WARNING unexpected `cfg` condition value
fn doc_with_value() {}
#[cfg(doc)]
fn doc() {}

View File

@ -1,53 +1,225 @@
warning: unexpected `cfg` condition value: `linuz`
--> $DIR/well-known-values.rs:7:7
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:26:5
|
LL | #[cfg(target_os = "linuz")]
LL | debug_assertions = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^----------------------
| |
| help: remove the value
|
= note: no expected value for `debug_assertions`
= note: `#[warn(unexpected_cfgs)]` on by default
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:28:5
|
LL | doc = "_UNEXPECTED_VALUE",
| ^^^----------------------
| |
| help: remove the value
|
= note: no expected value for `doc`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:30:5
|
LL | doctest = "_UNEXPECTED_VALUE",
| ^^^^^^^----------------------
| |
| help: remove the value
|
= note: no expected value for `doctest`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:32:5
|
LL | miri = "_UNEXPECTED_VALUE",
| ^^^^----------------------
| |
| help: remove the value
|
= note: no expected value for `miri`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:34:5
|
LL | overflow_checks = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^----------------------
| |
| help: remove the value
|
= note: no expected value for `overflow_checks`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:36:5
|
LL | panic = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `panic` are: `abort`, `unwind`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:38:5
|
LL | proc_macro = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^----------------------
| |
| help: remove the value
|
= note: no expected value for `proc_macro`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:40:5
|
LL | relocation_model = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `relocation_model` are: `dynamic-no-pic`, `pic`, `pie`, `ropi`, `ropi-rwpi`, `rwpi`, `static`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:42:5
|
LL | sanitize = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `sanitize` are: `address`, `cfi`, `hwaddress`, `kcfi`, `kernel-address`, `leak`, `memory`, `memtag`, `safestack`, `shadow-call-stack`, `thread`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:44:5
|
LL | target_abi = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `target_abi` are: ``, `abi64`, `abiv2`, `abiv2hf`, `eabi`, `eabihf`, `elf`, `fortanix`, `ilp32`, `llvm`, `macabi`, `sim`, `softfloat`, `spe`, `uwp`, `vec-extabi`, `x32`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:46:5
|
LL | target_arch = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `target_arch` are: `aarch64`, `arm`, `avr`, `bpf`, `csky`, `hexagon`, `loongarch64`, `m68k`, `mips`, `mips32r6`, `mips64`, `mips64r6`, `msp430`, `nvptx64`, `powerpc`, `powerpc64`, `riscv32`, `riscv64`, `s390x`, `sparc`, `sparc64`, `wasm32`, `wasm64`, `x86`, `x86_64`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:48:5
|
LL | target_endian = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `target_endian` are: `big`, `little`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:50:5
|
LL | target_env = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `target_env` are: ``, `eabihf`, `gnu`, `gnueabihf`, `msvc`, `musl`, `newlib`, `nto70`, `nto71`, `ohos`, `psx`, `relibc`, `sgx`, `uclibc`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:52:5
|
LL | target_family = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `target_family` are: `unix`, `wasm`, `windows`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:55:5
|
LL | target_has_atomic = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `target_has_atomic` are: (none), `128`, `16`, `32`, `64`, `8`, `ptr`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:57:5
|
LL | target_has_atomic_equal_alignment = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `target_has_atomic_equal_alignment` are: (none), `128`, `16`, `32`, `64`, `8`, `ptr`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:59:5
|
LL | target_has_atomic_load_store = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `target_has_atomic_load_store` are: (none), `128`, `16`, `32`, `64`, `8`, `ptr`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:61:5
|
LL | target_os = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:63:5
|
LL | target_pointer_width = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `target_pointer_width` are: `16`, `32`, `64`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:65:5
|
LL | target_thread_local = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^----------------------
| |
| help: remove the value
|
= note: no expected value for `target_thread_local`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:67:5
|
LL | target_vendor = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `target_vendor` are: `apple`, `espressif`, `fortanix`, `ibm`, `kmc`, `nintendo`, `nvidia`, `pc`, `sony`, `sun`, `unikraft`, `unknown`, `uwp`, `win7`, `wrs`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:69:5
|
LL | test = "_UNEXPECTED_VALUE",
| ^^^^----------------------
| |
| help: remove the value
|
= note: no expected value for `test`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:71:5
|
LL | unix = "_UNEXPECTED_VALUE",
| ^^^^----------------------
| |
| help: remove the value
|
= note: no expected value for `unix`
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
--> $DIR/well-known-values.rs:73:5
|
LL | windows = "_UNEXPECTED_VALUE",
| ^^^^^^^----------------------
| |
| help: remove the value
|
= note: no expected value for `windows`
warning: unexpected `cfg` condition value: `linuz`
--> $DIR/well-known-values.rs:79:7
|
LL | #[cfg(target_os = "linuz")] // testing that we suggest `linux`
| ^^^^^^^^^^^^-------
| |
| help: there is a expected value with a similar name: `"linux"`
|
= note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`
= note: `#[warn(unexpected_cfgs)]` on by default
warning: unexpected `cfg` condition value: `0`
--> $DIR/well-known-values.rs:14:7
|
LL | #[cfg(target_has_atomic = "0")]
| ^^^^^^^^^^^^^^^^^^^^---
| |
| help: there is a expected value with a similar name: `"8"`
|
= note: expected values for `target_has_atomic` are: (none), `128`, `16`, `32`, `64`, `8`, `ptr`
warning: unexpected `cfg` condition value: `aa`
--> $DIR/well-known-values.rs:21:7
|
LL | #[cfg(unix = "aa")]
| ^^^^-------
| |
| help: remove the value
|
= note: no expected value for `unix`
warning: unexpected `cfg` condition value: `miri`
--> $DIR/well-known-values.rs:28:7
|
LL | #[cfg(miri = "miri")]
| ^^^^---------
| |
| help: remove the value
|
= note: no expected value for `miri`
warning: unexpected `cfg` condition value: `linux`
--> $DIR/well-known-values.rs:35:7
|
LL | #[cfg(doc = "linux")]
| ^^^----------
| |
| help: remove the value
|
= note: no expected value for `doc`
warning: 5 warnings emitted
warning: 25 warnings emitted