@@ -30,7 +30,7 @@ pub(super) fn parse_cfg_name_directive<'a>(
3030 let mut outcome = MatchOutcome :: Invalid ;
3131 let mut message = None ;
3232
33- macro_rules! maybe_condition {
33+ macro_rules! condition {
3434 (
3535 name: $name: expr,
3636 $( allowed_names: $allowed_names: expr, ) ?
@@ -42,7 +42,7 @@ pub(super) fn parse_cfg_name_directive<'a>(
4242
4343 if outcome != MatchOutcome :: Invalid {
4444 // Ignore all other matches if we already found one
45- } else if $name. as_ref ( ) . map ( |n| n == & name) . unwrap_or ( false ) {
45+ } else if $name. custom_matches ( name) {
4646 message = Some ( format_message( ) ) ;
4747 if true $( && $condition) ? {
4848 outcome = MatchOutcome :: Match ;
@@ -56,21 +56,6 @@ pub(super) fn parse_cfg_name_directive<'a>(
5656 } ) ?
5757 } } ;
5858 }
59- macro_rules! condition {
60- (
61- name: $name: expr,
62- $( allowed_names: $allowed_names: expr, ) ?
63- $( condition: $condition: expr, ) ?
64- message: $( $message: tt) *
65- ) => {
66- maybe_condition! {
67- name: Some ( $name) ,
68- $( allowed_names: $allowed_names, ) *
69- $( condition: $condition, ) *
70- message: $( $message) *
71- }
72- } ;
73- }
7459
7560 let target_cfgs = config. target_cfgs ( ) ;
7661 let target_cfg = config. target_cfg ( ) ;
@@ -109,12 +94,10 @@ pub(super) fn parse_cfg_name_directive<'a>(
10994 allowed_names: & target_cfgs. all_pointer_widths,
11095 message: "when the pointer width is {name}"
11196 }
112- for family in & target_cfg. families {
113- condition ! {
114- name: family,
115- allowed_names: & target_cfgs. all_families,
116- message: "when the target family is {name}"
117- }
97+ condition ! {
98+ name: & * target_cfg. families,
99+ allowed_names: & target_cfgs. all_families,
100+ message: "when the target family is {name}"
118101 }
119102
120103 // If something is ignored for emscripten, it likely also needs to be
@@ -174,12 +157,12 @@ pub(super) fn parse_cfg_name_directive<'a>(
174157 condition: cfg!( debug_assertions) ,
175158 message: "when building with debug assertions" ,
176159 }
177- maybe_condition ! {
160+ condition ! {
178161 name: config. debugger. as_ref( ) . map( |d| d. to_str( ) ) ,
179162 allowed_names: & Debugger :: STR_VARIANTS ,
180163 message: "when the debugger is {name}" ,
181164 }
182- maybe_condition ! {
165+ condition ! {
183166 name: config. compare_mode
184167 . as_ref( )
185168 . map( |d| format!( "compare-mode-{}" , d. to_str( ) ) ) ,
@@ -281,3 +264,34 @@ impl<A: CustomContains, B: CustomContains> CustomContains for ContainsEither<'_,
281264 self . a . custom_contains ( item) || self . b . custom_contains ( item)
282265 }
283266}
267+
268+ trait CustomMatches {
269+ fn custom_matches ( & self , name : & str ) -> bool ;
270+ }
271+
272+ impl CustomMatches for & str {
273+ fn custom_matches ( & self , name : & str ) -> bool {
274+ name == * self
275+ }
276+ }
277+
278+ impl CustomMatches for String {
279+ fn custom_matches ( & self , name : & str ) -> bool {
280+ name == self
281+ }
282+ }
283+
284+ impl < T : CustomMatches > CustomMatches for & [ T ] {
285+ fn custom_matches ( & self , name : & str ) -> bool {
286+ self . iter ( ) . any ( |m| m. custom_matches ( name) )
287+ }
288+ }
289+
290+ impl < T : CustomMatches > CustomMatches for Option < T > {
291+ fn custom_matches ( & self , name : & str ) -> bool {
292+ match self {
293+ Some ( inner) => inner. custom_matches ( name) ,
294+ None => false ,
295+ }
296+ }
297+ }
0 commit comments