Skip to content

Commit

Permalink
Strengthen well known check-cfg names and values test
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Dec 7, 2023
1 parent 568f6a8 commit 5bfb9f5
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 74 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/check-cfg/compact-values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#[cfg(target(os = "linux", arch = "arm"))]
pub fn expected() {}

#[cfg(target(os = "linux", arch = "X"))]
#[cfg(target(os = "linux", pointer_width = "X"))]
//~^ WARNING unexpected `cfg` condition value
pub fn unexpected() {}

Expand Down
6 changes: 3 additions & 3 deletions tests/ui/check-cfg/compact-values.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
warning: unexpected `cfg` condition value: `X`
--> $DIR/compact-values.rs:11:28
|
LL | #[cfg(target(os = "linux", arch = "X"))]
| ^^^^^^^^^^
LL | #[cfg(target(os = "linux", pointer_width = "X"))]
| ^^^^^^^^^^^^^^^^^^^
|
= 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`
= note: expected values for `target_pointer_width` are: `16`, `32`, `64`
= note: `#[warn(unexpected_cfgs)]` on by default

warning: 1 warning emitted
Expand Down
4 changes: 0 additions & 4 deletions tests/ui/check-cfg/values-target-json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
#[lang = "sized"]
trait Sized {}

#[cfg(target_os = "linuz")]
//~^ WARNING unexpected `cfg` condition value
fn target_os_linux_misspell() {}

#[cfg(target_os = "linux")]
fn target_os_linux() {}

Expand Down
13 changes: 0 additions & 13 deletions tests/ui/check-cfg/values-target-json.stderr

This file was deleted.

85 changes: 67 additions & 18 deletions tests/ui/check-cfg/well-known-values.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,90 @@
// 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 recogniez 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

#![feature(cfg_overflow_checks)]
#![feature(cfg_target_has_atomic)]
#![feature(cfg_target_has_atomic_equal_alignment)]
#![feature(cfg_target_abi)]
#![feature(cfg_relocation_model)]
#![feature(cfg_sanitize)]
#![feature(cfg_target_thread_local)]

#[cfg(any(
doc = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
miri = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
unix = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
test = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
doctest = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
windows = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
proc_macro = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
panic = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
sanitize = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
relocation_model = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
debug_assertions = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
overflow_checks = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_thread_local = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_feature = "_UNEXPECTED_VALUE", // currently no values are checked
target_os = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_family = "_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_abi = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_vendor = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_pointer_width = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_has_atomic = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_has_atomic_load_store = "_UNEXPECTED_VALUE",
//~^ WARN unexpected `cfg` condition value
target_has_atomic_equal_alignment = "_UNEXPECTED_VALUE"
//~^ WARN unexpected `cfg` condition value
))]
fn unexpected_values() {}

// testing that we suggest `linux`
#[cfg(target_os = "linuz")]
//~^ WARNING unexpected `cfg` condition value
fn target_os_linux_misspell() {}

#[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() {}

#[cfg(unix = "aa")]
//~^ WARNING unexpected `cfg` condition value
fn unix_with_value() {}

#[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() {}

Expand Down
Loading

0 comments on commit 5bfb9f5

Please sign in to comment.