properly match multiple families
This commit is contained in:
parent
4cdb783cb9
commit
91be8cadcb
1 changed files with 39 additions and 25 deletions
|
@ -30,7 +30,7 @@ pub(super) fn parse_cfg_name_directive<'a>(
|
||||||
let mut outcome = MatchOutcome::Invalid;
|
let mut outcome = MatchOutcome::Invalid;
|
||||||
let mut message = None;
|
let mut message = None;
|
||||||
|
|
||||||
macro_rules! maybe_condition {
|
macro_rules! condition {
|
||||||
(
|
(
|
||||||
name: $name:expr,
|
name: $name:expr,
|
||||||
$(allowed_names: $allowed_names:expr,)?
|
$(allowed_names: $allowed_names:expr,)?
|
||||||
|
@ -42,7 +42,7 @@ pub(super) fn parse_cfg_name_directive<'a>(
|
||||||
|
|
||||||
if outcome != MatchOutcome::Invalid {
|
if outcome != MatchOutcome::Invalid {
|
||||||
// Ignore all other matches if we already found one
|
// Ignore all other matches if we already found one
|
||||||
} else if $name.as_ref().map(|n| n == &name).unwrap_or(false) {
|
} else if $name.custom_matches(name) {
|
||||||
message = Some(format_message());
|
message = Some(format_message());
|
||||||
if true $(&& $condition)? {
|
if true $(&& $condition)? {
|
||||||
outcome = MatchOutcome::Match;
|
outcome = MatchOutcome::Match;
|
||||||
|
@ -56,21 +56,6 @@ pub(super) fn parse_cfg_name_directive<'a>(
|
||||||
})?
|
})?
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
macro_rules! condition {
|
|
||||||
(
|
|
||||||
name: $name:expr,
|
|
||||||
$(allowed_names: $allowed_names:expr,)?
|
|
||||||
$(condition: $condition:expr,)?
|
|
||||||
message: $($message:tt)*
|
|
||||||
) => {
|
|
||||||
maybe_condition! {
|
|
||||||
name: Some($name),
|
|
||||||
$(allowed_names: $allowed_names,)*
|
|
||||||
$(condition: $condition,)*
|
|
||||||
message: $($message)*
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
let target_cfgs = config.target_cfgs();
|
let target_cfgs = config.target_cfgs();
|
||||||
let target_cfg = config.target_cfg();
|
let target_cfg = config.target_cfg();
|
||||||
|
@ -109,12 +94,10 @@ pub(super) fn parse_cfg_name_directive<'a>(
|
||||||
allowed_names: &target_cfgs.all_pointer_widths,
|
allowed_names: &target_cfgs.all_pointer_widths,
|
||||||
message: "when the pointer width is {name}"
|
message: "when the pointer width is {name}"
|
||||||
}
|
}
|
||||||
for family in &target_cfg.families {
|
condition! {
|
||||||
condition! {
|
name: &*target_cfg.families,
|
||||||
name: family,
|
allowed_names: &target_cfgs.all_families,
|
||||||
allowed_names: &target_cfgs.all_families,
|
message: "when the target family is {name}"
|
||||||
message: "when the target family is {name}"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If something is ignored for emscripten, it likely also needs to be
|
// If something is ignored for emscripten, it likely also needs to be
|
||||||
|
@ -174,12 +157,12 @@ pub(super) fn parse_cfg_name_directive<'a>(
|
||||||
condition: cfg!(debug_assertions),
|
condition: cfg!(debug_assertions),
|
||||||
message: "when building with debug assertions",
|
message: "when building with debug assertions",
|
||||||
}
|
}
|
||||||
maybe_condition! {
|
condition! {
|
||||||
name: config.debugger.as_ref().map(|d| d.to_str()),
|
name: config.debugger.as_ref().map(|d| d.to_str()),
|
||||||
allowed_names: &Debugger::STR_VARIANTS,
|
allowed_names: &Debugger::STR_VARIANTS,
|
||||||
message: "when the debugger is {name}",
|
message: "when the debugger is {name}",
|
||||||
}
|
}
|
||||||
maybe_condition! {
|
condition! {
|
||||||
name: config.compare_mode
|
name: config.compare_mode
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|d| format!("compare-mode-{}", d.to_str())),
|
.map(|d| format!("compare-mode-{}", d.to_str())),
|
||||||
|
@ -281,3 +264,34 @@ impl<A: CustomContains, B: CustomContains> CustomContains for ContainsEither<'_,
|
||||||
self.a.custom_contains(item) || self.b.custom_contains(item)
|
self.a.custom_contains(item) || self.b.custom_contains(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trait CustomMatches {
|
||||||
|
fn custom_matches(&self, name: &str) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CustomMatches for &str {
|
||||||
|
fn custom_matches(&self, name: &str) -> bool {
|
||||||
|
name == *self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CustomMatches for String {
|
||||||
|
fn custom_matches(&self, name: &str) -> bool {
|
||||||
|
name == self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: CustomMatches> CustomMatches for &[T] {
|
||||||
|
fn custom_matches(&self, name: &str) -> bool {
|
||||||
|
self.iter().any(|m| m.custom_matches(name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: CustomMatches> CustomMatches for Option<T> {
|
||||||
|
fn custom_matches(&self, name: &str) -> bool {
|
||||||
|
match self {
|
||||||
|
Some(inner) => inner.custom_matches(name),
|
||||||
|
None => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue