Skip to content

Commit

Permalink
Rollup merge of rust-lang#118702 - Urgau:check-cfg-strengthen-well-kn…
Browse files Browse the repository at this point in the history
…own, r=nnethercote

Strengthen well known check-cfg names and values test

rust-lang#118494 is changing the implementation of how we expect well known check-cfg names and values, but we currently don't have a test that checks every well known only some of them.

This PR therefore strengthen our well known names/values test to include all of the configs to at least avoid unintended regressions and validate new entry.

*this PR also contains some drive-by consolidation of unexpected `target_os`, `target_arch` into a single file*

r? ``@nnethercote`` (maybe? feel free to re-assign)
  • Loading branch information
GuillaumeGomez authored Dec 8, 2023
2 parents 09f6376 + 5a17ee7 commit 6b8512e
Show file tree
Hide file tree
Showing 7 changed files with 298 additions and 77 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.

107 changes: 85 additions & 22 deletions tests/ui/check-cfg/well-known-values.rs
Original file line number Diff line number Diff line change
@@ -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() {}

Expand Down
Loading

0 comments on commit 6b8512e

Please sign in to comment.