1
- use crate :: common:: { Config , CompareMode , Debugger } ;
1
+ use crate :: common:: { CompareMode , Config , Debugger } ;
2
2
use std:: collections:: HashSet ;
3
3
4
4
/// Parses a name-value directive which contains config-specific information, e.g., `ignore-x86`
@@ -48,7 +48,7 @@ pub(super) fn parse_cfg_name_directive<'a>(
48
48
outcome = MatchOutcome :: NoMatch ;
49
49
}
50
50
}
51
- $( else if $allowed_names. contains ( name) {
51
+ $( else if $allowed_names. custom_contains ( name) {
52
52
message = Some ( format_message( ) ) ;
53
53
outcome = MatchOutcome :: NoMatch ;
54
54
} ) ?
@@ -69,13 +69,6 @@ pub(super) fn parse_cfg_name_directive<'a>(
69
69
}
70
70
} ;
71
71
}
72
- macro_rules! hashset {
73
- ( $( $value: expr) ,* $( , ) ?) => { {
74
- let mut set = HashSet :: new( ) ;
75
- $( set. insert( $value) ; ) *
76
- set
77
- } }
78
- }
79
72
80
73
let target_cfgs = config. target_cfgs ( ) ;
81
74
let target_cfg = config. target_cfg ( ) ;
@@ -140,7 +133,7 @@ pub(super) fn parse_cfg_name_directive<'a>(
140
133
141
134
condition ! {
142
135
name: & config. channel,
143
- allowed_names: hashset! [ "stable" , "beta" , "nightly" ] ,
136
+ allowed_names: & [ "stable" , "beta" , "nightly" ] ,
144
137
message: "when the release channel is {name}" ,
145
138
}
146
139
condition ! {
@@ -155,7 +148,7 @@ pub(super) fn parse_cfg_name_directive<'a>(
155
148
}
156
149
condition ! {
157
150
name: config. stage_id. split( '-' ) . next( ) . unwrap( ) ,
158
- allowed_names: hashset! [ "stable" , "beta" , "nightly" ] ,
151
+ allowed_names: & [ "stable" , "beta" , "nightly" ] ,
159
152
message: "when the bootstrapping stage is {name}" ,
160
153
}
161
154
condition ! {
@@ -170,20 +163,17 @@ pub(super) fn parse_cfg_name_directive<'a>(
170
163
}
171
164
maybe_condition ! {
172
165
name: config. debugger. as_ref( ) . map( |d| d. to_str( ) ) ,
173
- allowed_names: Debugger :: VARIANTS
174
- . iter( )
175
- . map( |v| v. to_str( ) )
176
- . collect:: <HashSet <_>>( ) ,
166
+ allowed_names: & Debugger :: STR_VARIANTS ,
177
167
message: "when the debugger is {name}" ,
178
168
}
179
169
maybe_condition ! {
180
170
name: config. compare_mode
181
171
. as_ref( )
182
172
. map( |d| format!( "compare-mode-{}" , d. to_str( ) ) ) ,
183
- allowed_names: CompareMode :: VARIANTS
184
- . iter ( )
185
- . map ( |cm| format! ( "compare-mode-{}" , cm . to_str ( ) ) )
186
- . collect :: < HashSet <_>> ( ) ,
173
+ allowed_names: ContainsPrefixed {
174
+ prefix : "compare-mode-" ,
175
+ inner : CompareMode :: STR_VARIANTS ,
176
+ } ,
187
177
message: "when comparing with {name}" ,
188
178
}
189
179
@@ -231,3 +221,39 @@ pub(super) enum MatchOutcome {
231
221
/// The directive is handled by other parts of our tooling.
232
222
External ,
233
223
}
224
+
225
+ trait CustomContains {
226
+ fn custom_contains ( & self , item : & str ) -> bool ;
227
+ }
228
+
229
+ impl CustomContains for HashSet < String > {
230
+ fn custom_contains ( & self , item : & str ) -> bool {
231
+ self . contains ( item)
232
+ }
233
+ }
234
+
235
+ impl CustomContains for & [ & str ] {
236
+ fn custom_contains ( & self , item : & str ) -> bool {
237
+ self . contains ( & item)
238
+ }
239
+ }
240
+
241
+ impl < const N : usize > CustomContains for [ & str ; N ] {
242
+ fn custom_contains ( & self , item : & str ) -> bool {
243
+ self . contains ( & item)
244
+ }
245
+ }
246
+
247
+ struct ContainsPrefixed < T : CustomContains > {
248
+ prefix : & ' static str ,
249
+ inner : T ,
250
+ }
251
+
252
+ impl < T : CustomContains > CustomContains for ContainsPrefixed < T > {
253
+ fn custom_contains ( & self , item : & str ) -> bool {
254
+ match item. strip_prefix ( self . prefix ) {
255
+ Some ( stripped) => self . inner . custom_contains ( stripped) ,
256
+ None => false ,
257
+ }
258
+ }
259
+ }
0 commit comments