Skip to content

Commit 682534f

Browse files
committed
Add compile-time tests against unexpected target features cfgs
1 parent 4f10541 commit 682534f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Diff for: crates/std_detect/src/detect/macros.rs

+24
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ macro_rules! detect_feature {
1414
};
1515
}
1616

17+
#[allow(unused_macros, reason = "it's used in the features! macro below")]
18+
macro_rules! check_cfg_feature {
19+
($feature:tt, $feature_lit:tt) => {
20+
check_cfg_feature!($feature, $feature_lit : $feature_lit)
21+
};
22+
($feature:tt, $feature_lit:tt : $($target_feature_lit:tt),*) => {
23+
$(cfg!(target_feature = $target_feature_lit);)*
24+
};
25+
($feature:tt, $feature_lit:tt, without cfg check: $feature_cfg_check:literal) => {
26+
// FIXME: Enable once rust-lang/rust#132577 hit's nightly
27+
// #[expect(unexpected_cfgs, reason = $feature_lit)]
28+
// { cfg!(target_feature = $feature_lit) }
29+
};
30+
}
31+
1732
#[allow(unused)]
1833
macro_rules! features {
1934
(
@@ -117,6 +132,15 @@ macro_rules! features {
117132
};
118133
}
119134

135+
#[test]
136+
#[deny(unexpected_cfgs)]
137+
#[deny(unfulfilled_lint_expectations)]
138+
fn unexpected_cfgs() {
139+
$(
140+
check_cfg_feature!($feature, $feature_lit $(, without cfg check: $feature_cfg_check)? $(: $($target_feature_lit),*)?);
141+
)*
142+
}
143+
120144
/// Each variant denotes a position in a bitset for a particular feature.
121145
///
122146
/// PLEASE: do not use this, it is an implementation detail subject

0 commit comments

Comments
 (0)