@@ -30,7 +30,7 @@ pub(super) fn parse_cfg_name_directive<'a>(
30
30
let mut outcome = MatchOutcome :: Invalid ;
31
31
let mut message = None ;
32
32
33
- macro_rules! maybe_condition {
33
+ macro_rules! condition {
34
34
(
35
35
name: $name: expr,
36
36
$( allowed_names: $allowed_names: expr, ) ?
@@ -42,7 +42,7 @@ pub(super) fn parse_cfg_name_directive<'a>(
42
42
43
43
if outcome != MatchOutcome :: Invalid {
44
44
// 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) {
46
46
message = Some ( format_message( ) ) ;
47
47
if true $( && $condition) ? {
48
48
outcome = MatchOutcome :: Match ;
@@ -56,21 +56,6 @@ pub(super) fn parse_cfg_name_directive<'a>(
56
56
} ) ?
57
57
} } ;
58
58
}
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
- }
74
59
75
60
let target_cfgs = config. target_cfgs ( ) ;
76
61
let target_cfg = config. target_cfg ( ) ;
@@ -109,12 +94,10 @@ pub(super) fn parse_cfg_name_directive<'a>(
109
94
allowed_names: & target_cfgs. all_pointer_widths,
110
95
message: "when the pointer width is {name}"
111
96
}
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}"
118
101
}
119
102
120
103
// If something is ignored for emscripten, it likely also needs to be
@@ -174,12 +157,12 @@ pub(super) fn parse_cfg_name_directive<'a>(
174
157
condition: cfg!( debug_assertions) ,
175
158
message: "when building with debug assertions" ,
176
159
}
177
- maybe_condition ! {
160
+ condition ! {
178
161
name: config. debugger. as_ref( ) . map( |d| d. to_str( ) ) ,
179
162
allowed_names: & Debugger :: STR_VARIANTS ,
180
163
message: "when the debugger is {name}" ,
181
164
}
182
- maybe_condition ! {
165
+ condition ! {
183
166
name: config. compare_mode
184
167
. as_ref( )
185
168
. map( |d| format!( "compare-mode-{}" , d. to_str( ) ) ) ,
@@ -281,3 +264,34 @@ impl<A: CustomContains, B: CustomContains> CustomContains for ContainsEither<'_,
281
264
self . a . custom_contains ( item) || self . b . custom_contains ( item)
282
265
}
283
266
}
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