1- use crate :: common:: { Config , CompareMode , Debugger } ;
1+ use crate :: common:: { CompareMode , Config , Debugger } ;
22use std:: collections:: HashSet ;
33
44/// 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>(
4848 outcome = MatchOutcome :: NoMatch ;
4949 }
5050 }
51- $( else if $allowed_names. contains ( name) {
51+ $( else if $allowed_names. custom_contains ( name) {
5252 message = Some ( format_message( ) ) ;
5353 outcome = MatchOutcome :: NoMatch ;
5454 } ) ?
@@ -69,13 +69,6 @@ pub(super) fn parse_cfg_name_directive<'a>(
6969 }
7070 } ;
7171 }
72- macro_rules! hashset {
73- ( $( $value: expr) ,* $( , ) ?) => { {
74- let mut set = HashSet :: new( ) ;
75- $( set. insert( $value) ; ) *
76- set
77- } }
78- }
7972
8073 let target_cfgs = config. target_cfgs ( ) ;
8174 let target_cfg = config. target_cfg ( ) ;
@@ -140,7 +133,7 @@ pub(super) fn parse_cfg_name_directive<'a>(
140133
141134 condition ! {
142135 name: & config. channel,
143- allowed_names: hashset! [ "stable" , "beta" , "nightly" ] ,
136+ allowed_names: & [ "stable" , "beta" , "nightly" ] ,
144137 message: "when the release channel is {name}" ,
145138 }
146139 condition ! {
@@ -155,7 +148,7 @@ pub(super) fn parse_cfg_name_directive<'a>(
155148 }
156149 condition ! {
157150 name: config. stage_id. split( '-' ) . next( ) . unwrap( ) ,
158- allowed_names: hashset! [ "stable" , "beta" , "nightly" ] ,
151+ allowed_names: & [ "stable" , "beta" , "nightly" ] ,
159152 message: "when the bootstrapping stage is {name}" ,
160153 }
161154 condition ! {
@@ -170,20 +163,17 @@ pub(super) fn parse_cfg_name_directive<'a>(
170163 }
171164 maybe_condition ! {
172165 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 ,
177167 message: "when the debugger is {name}" ,
178168 }
179169 maybe_condition ! {
180170 name: config. compare_mode
181171 . as_ref( )
182172 . 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+ } ,
187177 message: "when comparing with {name}" ,
188178 }
189179
@@ -231,3 +221,39 @@ pub(super) enum MatchOutcome {
231221 /// The directive is handled by other parts of our tooling.
232222 External ,
233223}
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