Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strengthen well known check-cfg names and values test #118702

Merged
merged 2 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.
Urgau marked this conversation as resolved.
Show resolved Hide resolved

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

Urgau marked this conversation as resolved.
Show resolved Hide resolved
#[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
Loading