@@ -8,170 +8,190 @@ pub(super) fn handle_needs(
88) -> IgnoreDecision {
99 // Note thet we intentionally still put the needs- prefix here to make the file show up when
1010 // grepping for a directive name, even though we could technically strip that.
11- let needs = & [
11+ let needs = & mut [
1212 Need {
1313 name : "needs-asm-support" ,
14- condition : config. has_asm_support ( ) ,
14+ condition : & mut |_| config. has_asm_support ( ) . then_some ( IgnoreDecision :: Continue ) ,
1515 ignore_reason : "ignored on targets without inline assembly support" ,
1616 } ,
1717 Need {
1818 name : "needs-sanitizer-support" ,
19- condition : cache. sanitizer_support ,
19+ condition : & mut |_| cache. sanitizer_support . then_some ( IgnoreDecision :: Continue ) ,
2020 ignore_reason : "ignored on targets without sanitizers support" ,
2121 } ,
2222 Need {
2323 name : "needs-sanitizer-address" ,
24- condition : cache. sanitizer_address ,
24+ condition : & mut |_| cache. sanitizer_address . then_some ( IgnoreDecision :: Continue ) ,
2525 ignore_reason : "ignored on targets without address sanitizer" ,
2626 } ,
2727 Need {
2828 name : "needs-sanitizer-cfi" ,
29- condition : cache. sanitizer_cfi ,
29+ condition : & mut |_| cache. sanitizer_cfi . then_some ( IgnoreDecision :: Continue ) ,
3030 ignore_reason : "ignored on targets without CFI sanitizer" ,
3131 } ,
3232 Need {
3333 name : "needs-sanitizer-dataflow" ,
34- condition : cache. sanitizer_dataflow ,
34+ condition : & mut |_| cache. sanitizer_dataflow . then_some ( IgnoreDecision :: Continue ) ,
3535 ignore_reason : "ignored on targets without dataflow sanitizer" ,
3636 } ,
3737 Need {
3838 name : "needs-sanitizer-kcfi" ,
39- condition : cache. sanitizer_kcfi ,
39+ condition : & mut |_| cache. sanitizer_kcfi . then_some ( IgnoreDecision :: Continue ) ,
4040 ignore_reason : "ignored on targets without kernel CFI sanitizer" ,
4141 } ,
4242 Need {
4343 name : "needs-sanitizer-kasan" ,
44- condition : cache. sanitizer_kasan ,
44+ condition : & mut |_| cache. sanitizer_kasan . then_some ( IgnoreDecision :: Continue ) ,
4545 ignore_reason : "ignored on targets without kernel address sanitizer" ,
4646 } ,
4747 Need {
4848 name : "needs-sanitizer-leak" ,
49- condition : cache. sanitizer_leak ,
49+ condition : & mut |_| cache. sanitizer_leak . then_some ( IgnoreDecision :: Continue ) ,
5050 ignore_reason : "ignored on targets without leak sanitizer" ,
5151 } ,
5252 Need {
5353 name : "needs-sanitizer-memory" ,
54- condition : cache. sanitizer_memory ,
54+ condition : & mut |_| cache. sanitizer_memory . then_some ( IgnoreDecision :: Continue ) ,
5555 ignore_reason : "ignored on targets without memory sanitizer" ,
5656 } ,
5757 Need {
5858 name : "needs-sanitizer-thread" ,
59- condition : cache. sanitizer_thread ,
59+ condition : & mut |_| cache. sanitizer_thread . then_some ( IgnoreDecision :: Continue ) ,
6060 ignore_reason : "ignored on targets without thread sanitizer" ,
6161 } ,
6262 Need {
6363 name : "needs-sanitizer-hwaddress" ,
64- condition : cache. sanitizer_hwaddress ,
64+ condition : & mut |_| cache. sanitizer_hwaddress . then_some ( IgnoreDecision :: Continue ) ,
6565 ignore_reason : "ignored on targets without hardware-assisted address sanitizer" ,
6666 } ,
6767 Need {
6868 name : "needs-sanitizer-memtag" ,
69- condition : cache. sanitizer_memtag ,
69+ condition : & mut |_| cache. sanitizer_memtag . then_some ( IgnoreDecision :: Continue ) ,
7070 ignore_reason : "ignored on targets without memory tagging sanitizer" ,
7171 } ,
7272 Need {
7373 name : "needs-sanitizer-shadow-call-stack" ,
74- condition : cache. sanitizer_shadow_call_stack ,
74+ condition : & mut |_| {
75+ cache. sanitizer_shadow_call_stack . then_some ( IgnoreDecision :: Continue )
76+ } ,
7577 ignore_reason : "ignored on targets without shadow call stacks" ,
7678 } ,
7779 Need {
7880 name : "needs-sanitizer-safestack" ,
79- condition : cache. sanitizer_safestack ,
81+ condition : & mut |_| cache. sanitizer_safestack . then_some ( IgnoreDecision :: Continue ) ,
8082 ignore_reason : "ignored on targets without SafeStack support" ,
8183 } ,
8284 Need {
8385 name : "needs-enzyme" ,
84- condition : config. has_enzyme ,
86+ condition : & mut |_| config. has_enzyme . then_some ( IgnoreDecision :: Continue ) ,
8587 ignore_reason : "ignored when LLVM Enzyme is disabled" ,
8688 } ,
8789 Need {
8890 name : "needs-run-enabled" ,
89- condition : config. run_enabled ( ) ,
91+ condition : & mut |_| config. run_enabled ( ) . then_some ( IgnoreDecision :: Continue ) ,
9092 ignore_reason : "ignored when running the resulting test binaries is disabled" ,
9193 } ,
9294 Need {
9395 name : "needs-threads" ,
94- condition : config. has_threads ( ) ,
96+ condition : & mut |_| config. has_threads ( ) . then_some ( IgnoreDecision :: Continue ) ,
9597 ignore_reason : "ignored on targets without threading support" ,
9698 } ,
9799 Need {
98100 name : "needs-unwind" ,
99- condition : config. can_unwind ( ) ,
101+ condition : & mut |_| config. can_unwind ( ) . then_some ( IgnoreDecision :: Continue ) ,
100102 ignore_reason : "ignored on targets without unwinding support" ,
101103 } ,
102104 Need {
103105 name : "needs-profiler-runtime" ,
104- condition : config. profiler_runtime ,
106+ condition : & mut |_| config. profiler_runtime . then_some ( IgnoreDecision :: Continue ) ,
105107 ignore_reason : "ignored when the profiler runtime is not available" ,
106108 } ,
107109 Need {
108110 name : "needs-force-clang-based-tests" ,
109- condition : config. run_clang_based_tests_with . is_some ( ) ,
111+ condition : & mut |_| {
112+ config. run_clang_based_tests_with . is_some ( ) . then_some ( IgnoreDecision :: Continue )
113+ } ,
110114 ignore_reason : "ignored when RUSTBUILD_FORCE_CLANG_BASED_TESTS is not set" ,
111115 } ,
112116 Need {
113117 name : "needs-xray" ,
114- condition : cache. xray ,
118+ condition : & mut |_| cache. xray . then_some ( IgnoreDecision :: Continue ) ,
115119 ignore_reason : "ignored on targets without xray tracing" ,
116120 } ,
117121 Need {
118122 name : "needs-rust-lld" ,
119- condition : cache. rust_lld ,
123+ condition : & mut |_| cache. rust_lld . then_some ( IgnoreDecision :: Continue ) ,
120124 ignore_reason : "ignored on targets without Rust's LLD" ,
121125 } ,
122126 Need {
123127 name : "needs-dlltool" ,
124- condition : cache. dlltool ,
128+ condition : & mut |_| cache. dlltool . then_some ( IgnoreDecision :: Continue ) ,
125129 ignore_reason : "ignored when dlltool for the current architecture is not present" ,
126130 } ,
127131 Need {
128132 name : "needs-git-hash" ,
129- condition : config. git_hash ,
133+ condition : & mut |_| config. git_hash . then_some ( IgnoreDecision :: Continue ) ,
130134 ignore_reason : "ignored when git hashes have been omitted for building" ,
131135 } ,
132136 Need {
133137 name : "needs-dynamic-linking" ,
134- condition : config. target_cfg ( ) . dynamic_linking ,
138+ condition : & mut |_| {
139+ config. target_cfg ( ) . dynamic_linking . then_some ( IgnoreDecision :: Continue )
140+ } ,
135141 ignore_reason : "ignored on targets without dynamic linking" ,
136142 } ,
137143 Need {
138144 name : "needs-relocation-model-pic" ,
139- condition : config. target_cfg ( ) . relocation_model == "pic" ,
145+ condition : & mut |_| {
146+ ( config. target_cfg ( ) . relocation_model == "PIC" ) . then_some ( IgnoreDecision :: Continue )
147+ } ,
140148 ignore_reason : "ignored on targets without PIC relocation model" ,
141149 } ,
142150 Need {
143151 name : "needs-deterministic-layouts" ,
144- condition : !config. rust_randomized_layout ,
152+ condition : & mut |_| {
153+ ( !config. rust_randomized_layout ) . then_some ( IgnoreDecision :: Continue )
154+ } ,
145155 ignore_reason : "ignored when randomizing layouts" ,
146156 } ,
147157 Need {
148158 name : "needs-wasmtime" ,
149- condition : config. runner . as_ref ( ) . is_some_and ( |r| r. contains ( "wasmtime" ) ) ,
159+ condition : & mut |_| {
160+ config
161+ . runner
162+ . as_ref ( )
163+ . is_some_and ( |r| r. contains ( "wasmtime" ) )
164+ . then_some ( IgnoreDecision :: Continue )
165+ } ,
150166 ignore_reason : "ignored when wasmtime runner is not available" ,
151167 } ,
152168 Need {
153169 name : "needs-symlink" ,
154- condition : cache. symlinks ,
170+ condition : & mut |_| cache. symlinks . then_some ( IgnoreDecision :: Continue ) ,
155171 ignore_reason : "ignored if symlinks are unavailable" ,
156172 } ,
157173 Need {
158174 name : "needs-llvm-zstd" ,
159- condition : cache. llvm_zstd ,
175+ condition : & mut |_| cache. llvm_zstd . then_some ( IgnoreDecision :: Continue ) ,
160176 ignore_reason : "ignored if LLVM wasn't build with zstd for ELF section compression" ,
161177 } ,
162178 Need {
163179 name : "needs-rustc-debug-assertions" ,
164- condition : config. with_rustc_debug_assertions ,
180+ condition : & mut |_| {
181+ config. with_rustc_debug_assertions . then_some ( IgnoreDecision :: Continue )
182+ } ,
165183 ignore_reason : "ignored if rustc wasn't built with debug assertions" ,
166184 } ,
167185 Need {
168186 name : "needs-std-debug-assertions" ,
169- condition : config. with_std_debug_assertions ,
187+ condition : & mut |_| {
188+ config. with_std_debug_assertions . then_some ( IgnoreDecision :: Continue )
189+ } ,
170190 ignore_reason : "ignored if std wasn't built with debug assertions" ,
171191 } ,
172192 ] ;
173193
174- let ( name, comment) = match ln. split_once ( [ ':' , ' ' ] ) {
194+ let ( name, mut comment) = match ln. split_once ( [ ':' , ' ' ] ) {
175195 Some ( ( name, comment) ) => ( name, Some ( comment) ) ,
176196 None => ( ln, None ) ,
177197 } ;
@@ -185,34 +205,31 @@ pub(super) fn handle_needs(
185205 return IgnoreDecision :: Continue ;
186206 }
187207
188- let mut found_valid = false ;
189- for need in needs {
190- if need. name == name {
191- if need. condition {
192- found_valid = true ;
193- break ;
208+ needs
209+ . iter_mut ( )
210+ . find_map ( |need| {
211+ if need. name == name {
212+ ( need. condition ) ( & mut comment) . or_else ( || {
213+ Some ( IgnoreDecision :: Ignore {
214+ reason : if let Some ( comment) = comment {
215+ format ! ( "{} ({})" , need. ignore_reason, comment. trim( ) )
216+ } else {
217+ need. ignore_reason . into ( )
218+ } ,
219+ } )
220+ } )
194221 } else {
195- return IgnoreDecision :: Ignore {
196- reason : if let Some ( comment) = comment {
197- format ! ( "{} ({})" , need. ignore_reason, comment. trim( ) )
198- } else {
199- need. ignore_reason . into ( )
200- } ,
201- } ;
222+ None
202223 }
203- }
204- }
205-
206- if found_valid {
207- IgnoreDecision :: Continue
208- } else {
209- IgnoreDecision :: Error { message : format ! ( "invalid needs directive: {name}" ) }
210- }
224+ } )
225+ . unwrap_or_else ( || IgnoreDecision :: Error {
226+ message : format ! ( "invalid needs directive: {name}" ) ,
227+ } )
211228}
212229
213- struct Need {
230+ struct Need < ' a > {
214231 name : & ' static str ,
215- condition : bool ,
232+ condition : & ' a mut dyn FnMut ( & mut Option < & str > ) -> Option < IgnoreDecision > ,
216233 ignore_reason : & ' static str ,
217234}
218235
0 commit comments