Add ability to declare a feature without cfg checking

This is necessary to avoid `unexpected_cfgs` warnings for unexpected/
missing target features, in user code.
This commit is contained in:
Urgau
2024-11-05 20:31:40 +01:00
committed by Amanieu d'Antras
parent d3fe1b7c21
commit a6a49cfd90

View File

@@ -9,6 +9,9 @@ macro_rules! detect_feature {
$(cfg!(target_feature = $target_feature_lit) ||)* $(cfg!(target_feature = $target_feature_lit) ||)*
$crate::detect::__is_feature_detected::$feature() $crate::detect::__is_feature_detected::$feature()
}; };
($feature:tt, $feature_lit:tt, without cfg check: true) => {
$crate::detect::__is_feature_detected::$feature()
};
} }
#[allow(unused)] #[allow(unused)]
@@ -21,6 +24,7 @@ macro_rules! features {
$(@BIND_FEATURE_NAME: $bind_feature:tt; $feature_impl:tt; $(#[$deprecate_attr:meta];)?)* $(@BIND_FEATURE_NAME: $bind_feature:tt; $feature_impl:tt; $(#[$deprecate_attr:meta];)?)*
$(@NO_RUNTIME_DETECTION: $nort_feature:tt; )* $(@NO_RUNTIME_DETECTION: $nort_feature:tt; )*
$(@FEATURE: #[$stability_attr:meta] $feature:ident: $feature_lit:tt; $(@FEATURE: #[$stability_attr:meta] $feature:ident: $feature_lit:tt;
$(without cfg check: $feature_cfg_check:literal;)?
$(implied by target_features: [$($target_feature_lit:tt),*];)? $(implied by target_features: [$($target_feature_lit:tt),*];)?
$(#[$feature_comment:meta])*)* $(#[$feature_comment:meta])*)*
) => { ) => {
@@ -32,7 +36,7 @@ macro_rules! features {
macro_rules! $macro_name { macro_rules! $macro_name {
$( $(
($feature_lit) => { ($feature_lit) => {
$crate::detect_feature!($feature, $feature_lit $(: $($target_feature_lit),*)?) $crate::detect_feature!($feature, $feature_lit $(, without cfg check: $feature_cfg_check)? $(: $($target_feature_lit),*)?)
}; };
)* )*
$( $(