diff options
| author | Urgau <urgau@numericable.fr> | 2024-11-07 00:28:43 +0100 | 
|---|---|---|
| committer | Amanieu d'Antras <amanieu@gmail.com> | 2024-11-08 06:17:06 +0800 | 
| commit | 7956142f9288cb3117b2b7a6924f9106fe57dace (patch) | |
| tree | c5c2ad8d6ffb05283b613455c16ef5275262584d /library/stdarch/crates/std_detect/src/detect/macros.rs | |
| parent | f62e1daa2dfecc6fc3b20a24bc39a8c7fe84080a (diff) | |
| download | rust-7956142f9288cb3117b2b7a6924f9106fe57dace.tar.gz rust-7956142f9288cb3117b2b7a6924f9106fe57dace.zip | |
Add compile-time tests against unexpected target features cfgs
Diffstat (limited to 'library/stdarch/crates/std_detect/src/detect/macros.rs')
| -rw-r--r-- | library/stdarch/crates/std_detect/src/detect/macros.rs | 24 | 
1 files changed, 24 insertions, 0 deletions
| diff --git a/library/stdarch/crates/std_detect/src/detect/macros.rs b/library/stdarch/crates/std_detect/src/detect/macros.rs index f2cc711812a..38c8b8068fb 100644 --- a/library/stdarch/crates/std_detect/src/detect/macros.rs +++ b/library/stdarch/crates/std_detect/src/detect/macros.rs @@ -14,6 +14,21 @@ macro_rules! detect_feature { }; } +#[allow(unused_macros, reason = "it's used in the features! macro below")] +macro_rules! check_cfg_feature { + ($feature:tt, $feature_lit:tt) => { + check_cfg_feature!($feature, $feature_lit : $feature_lit) + }; + ($feature:tt, $feature_lit:tt : $($target_feature_lit:tt),*) => { + $(cfg!(target_feature = $target_feature_lit);)* + }; + ($feature:tt, $feature_lit:tt, without cfg check: $feature_cfg_check:literal) => { + // FIXME: Enable once rust-lang/rust#132577 hit's nightly + // #[expect(unexpected_cfgs, reason = $feature_lit)] + // { cfg!(target_feature = $feature_lit) } + }; +} + #[allow(unused)] macro_rules! features { ( @@ -117,6 +132,15 @@ macro_rules! features { }; } + #[test] + #[deny(unexpected_cfgs)] + #[deny(unfulfilled_lint_expectations)] + fn unexpected_cfgs() { + $( + check_cfg_feature!($feature, $feature_lit $(, without cfg check: $feature_cfg_check)? $(: $($target_feature_lit),*)?); + )* + } + /// Each variant denotes a position in a bitset for a particular feature. /// /// PLEASE: do not use this, it is an implementation detail subject | 
