2023-12-07 11:04:00 +00:00
|
|
|
// 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.
|
2022-02-25 15:10:26 +00:00
|
|
|
//
|
|
|
|
//@ check-pass
|
2024-04-09 12:07:30 +00:00
|
|
|
//@ no-auto-check-cfg
|
2024-02-25 13:56:14 +00:00
|
|
|
//@ compile-flags: --check-cfg=cfg()
|
2024-02-16 20:32:53 +00:00
|
|
|
//@ compile-flags: -Zcheck-cfg-all-expected
|
2022-02-25 15:10:26 +00:00
|
|
|
|
2023-12-07 11:04:00 +00:00
|
|
|
#![feature(cfg_overflow_checks)]
|
|
|
|
#![feature(cfg_relocation_model)]
|
|
|
|
#![feature(cfg_sanitize)]
|
|
|
|
#![feature(cfg_target_has_atomic)]
|
|
|
|
#![feature(cfg_target_has_atomic_equal_alignment)]
|
|
|
|
#![feature(cfg_target_thread_local)]
|
2024-04-03 12:54:03 +00:00
|
|
|
#![feature(cfg_ub_checks)]
|
2024-04-14 12:52:58 +00:00
|
|
|
#![feature(fmt_debug)]
|
2023-12-07 11:04:00 +00:00
|
|
|
|
|
|
|
// 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
|
2024-02-15 11:09:17 +00:00
|
|
|
clippy = "_UNEXPECTED_VALUE",
|
|
|
|
//~^ WARN unexpected `cfg` condition value
|
2023-12-07 11:04:00 +00:00
|
|
|
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
|
2024-04-14 12:52:58 +00:00
|
|
|
fmt_debug = "_UNEXPECTED_VALUE",
|
|
|
|
//~^ WARN unexpected `cfg` condition value
|
2023-12-07 11:04:00 +00:00
|
|
|
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
|
2024-05-05 10:23:51 +00:00
|
|
|
rustfmt = "_UNEXPECTED_VALUE",
|
|
|
|
//~^ WARN unexpected `cfg` condition value
|
2023-12-07 11:04:00 +00:00
|
|
|
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
|
2023-12-12 21:04:48 +00:00
|
|
|
target_feature = "_UNEXPECTED_VALUE",
|
|
|
|
//~^ WARN unexpected `cfg` condition value
|
2023-12-07 11:04:00 +00:00
|
|
|
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
|
2024-04-03 12:54:03 +00:00
|
|
|
ub_checks = "_UNEXPECTED_VALUE",
|
|
|
|
//~^ WARN unexpected `cfg` condition value
|
2023-12-07 11:04:00 +00:00
|
|
|
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`
|
2022-02-25 15:10:26 +00:00
|
|
|
//~^ WARNING unexpected `cfg` condition value
|
|
|
|
fn target_os_linux_misspell() {}
|
|
|
|
|
2023-12-07 11:04:00 +00:00
|
|
|
// 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...).
|
|
|
|
|
2022-02-25 15:10:26 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
fn target_os_linux() {}
|
|
|
|
|
2023-12-12 21:17:41 +00:00
|
|
|
#[cfg(target_feature = "crt-static")] // pure rustc feature
|
|
|
|
fn target_feature() {}
|
|
|
|
|
2022-02-25 15:10:26 +00:00
|
|
|
#[cfg(target_has_atomic = "8")]
|
2023-12-07 11:04:00 +00:00
|
|
|
fn target_has_atomic_8() {}
|
2022-02-25 15:10:26 +00:00
|
|
|
|
2023-12-07 11:04:00 +00:00
|
|
|
#[cfg(target_has_atomic)]
|
|
|
|
fn target_has_atomic() {}
|
2022-02-25 15:10:26 +00:00
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
fn unix() {}
|
|
|
|
|
2022-03-09 15:52:38 +00:00
|
|
|
#[cfg(doc)]
|
|
|
|
fn doc() {}
|
|
|
|
|
2024-02-15 11:09:17 +00:00
|
|
|
#[cfg(clippy)]
|
|
|
|
fn clippy() {}
|
|
|
|
|
2024-05-05 10:23:51 +00:00
|
|
|
#[cfg_attr(rustfmt, rustfmt::skip)]
|
|
|
|
fn rustfmt() {}
|
|
|
|
|
2022-02-25 15:10:26 +00:00
|
|
|
fn main() {}
|