1+ use test_common:: { CommentKind , TestComment } ;
2+
13use crate :: common:: { Config , Debugger } ;
24use crate :: header:: IgnoreDecision ;
35use crate :: util;
46
57pub ( super ) fn handle_needs (
68 cache : & CachedNeedsConditions ,
79 config : & Config ,
8- ln : & str ,
10+ comment : TestComment < ' _ > ,
911) -> IgnoreDecision {
1012 // Note that we intentionally still put the needs- prefix here to make the file show up when
1113 // grepping for a directive name, even though we could technically strip that.
1214 let needs = & [
1315 Need {
14- names : & [ "needs-asm-support" , "@needs-asm-support" ] ,
16+ compiletest_name : "needs-asm-support" ,
17+ ui_test_name : Some ( "needs-asm-support" ) ,
1518 condition : config. has_asm_support ( ) ,
1619 ignore_reason : "ignored on targets without inline assembly support" ,
1720 } ,
1821 Need {
19- names : & [ "needs-sanitizer-support" ] ,
22+ compiletest_name : "needs-sanitizer-support" ,
23+ ui_test_name : None ,
2024 condition : cache. sanitizer_support ,
2125 ignore_reason : "ignored on targets without sanitizers support" ,
2226 } ,
2327 Need {
24- names : & [ "needs-sanitizer-address" ] ,
28+ compiletest_name : "needs-sanitizer-address" ,
29+ ui_test_name : None ,
2530 condition : cache. sanitizer_address ,
2631 ignore_reason : "ignored on targets without address sanitizer" ,
2732 } ,
2833 Need {
29- names : & [ "needs-sanitizer-cfi" ] ,
34+ compiletest_name : "needs-sanitizer-cfi" ,
35+ ui_test_name : None ,
3036 condition : cache. sanitizer_cfi ,
3137 ignore_reason : "ignored on targets without CFI sanitizer" ,
3238 } ,
3339 Need {
34- names : & [ "needs-sanitizer-kcfi" ] ,
40+ compiletest_name : "needs-sanitizer-kcfi" ,
41+ ui_test_name : None ,
3542 condition : cache. sanitizer_kcfi ,
3643 ignore_reason : "ignored on targets without kernel CFI sanitizer" ,
3744 } ,
3845 Need {
39- names : & [ "needs-sanitizer-kasan" ] ,
46+ compiletest_name : "needs-sanitizer-kasan" ,
47+ ui_test_name : None ,
4048 condition : cache. sanitizer_kasan ,
4149 ignore_reason : "ignored on targets without kernel address sanitizer" ,
4250 } ,
4351 Need {
44- names : & [ "needs-sanitizer-leak" ] ,
52+ compiletest_name : "needs-sanitizer-leak" ,
53+ ui_test_name : None ,
4554 condition : cache. sanitizer_leak ,
4655 ignore_reason : "ignored on targets without leak sanitizer" ,
4756 } ,
4857 Need {
49- names : & [ "needs-sanitizer-memory" ] ,
58+ compiletest_name : "needs-sanitizer-memory" ,
59+ ui_test_name : None ,
5060 condition : cache. sanitizer_memory ,
5161 ignore_reason : "ignored on targets without memory sanitizer" ,
5262 } ,
5363 Need {
54- names : & [ "needs-sanitizer-thread" ] ,
64+ compiletest_name : "needs-sanitizer-thread" ,
65+ ui_test_name : None ,
5566 condition : cache. sanitizer_thread ,
5667 ignore_reason : "ignored on targets without thread sanitizer" ,
5768 } ,
5869 Need {
59- names : & [ "needs-sanitizer-hwaddress" ] ,
70+ compiletest_name : "needs-sanitizer-hwaddress" ,
71+ ui_test_name : None ,
6072 condition : cache. sanitizer_hwaddress ,
6173 ignore_reason : "ignored on targets without hardware-assisted address sanitizer" ,
6274 } ,
6375 Need {
64- names : & [ "needs-sanitizer-memtag" ] ,
76+ compiletest_name : "needs-sanitizer-memtag" ,
77+ ui_test_name : None ,
6578 condition : cache. sanitizer_memtag ,
6679 ignore_reason : "ignored on targets without memory tagging sanitizer" ,
6780 } ,
6881 Need {
69- names : & [ "needs-sanitizer-shadow-call-stack" ] ,
82+ compiletest_name : "needs-sanitizer-shadow-call-stack" ,
83+ ui_test_name : None ,
7084 condition : cache. sanitizer_shadow_call_stack ,
7185 ignore_reason : "ignored on targets without shadow call stacks" ,
7286 } ,
7387 Need {
74- names : & [ "needs-sanitizer-safestack" ] ,
88+ compiletest_name : "needs-sanitizer-safestack" ,
89+ ui_test_name : None ,
7590 condition : cache. sanitizer_safestack ,
7691 ignore_reason : "ignored on targets without SafeStack support" ,
7792 } ,
7893 Need {
79- names : & [ "needs-run-enabled" ] ,
94+ compiletest_name : "needs-run-enabled" ,
95+ ui_test_name : None ,
8096 condition : config. run_enabled ( ) ,
8197 ignore_reason : "ignored when running the resulting test binaries is disabled" ,
8298 } ,
8399 Need {
84- names : & [ "needs-unwind" ] ,
100+ compiletest_name : "needs-unwind" ,
101+ ui_test_name : None ,
85102 condition : config. can_unwind ( ) ,
86103 ignore_reason : "ignored on targets without unwinding support" ,
87104 } ,
88105 Need {
89- names : & [ "needs-profiler-support" ] ,
106+ compiletest_name : "needs-profiler-support" ,
107+ ui_test_name : None ,
90108 condition : cache. profiler_support ,
91109 ignore_reason : "ignored when profiler support is disabled" ,
92110 } ,
93111 Need {
94- names : & [ "needs-matching-clang" ] ,
112+ compiletest_name : "needs-matching-clang" ,
113+ ui_test_name : None ,
95114 condition : config. run_clang_based_tests_with . is_some ( ) ,
96115 ignore_reason : "ignored when the used clang does not match the built LLVM" ,
97116 } ,
98117 Need {
99- names : & [ "needs-xray" ] ,
118+ compiletest_name : "needs-xray" ,
119+ ui_test_name : None ,
100120 condition : cache. xray ,
101121 ignore_reason : "ignored on targets without xray tracing" ,
102122 } ,
103123 Need {
104- names : & [ "needs-rust-lld" ] ,
124+ compiletest_name : "needs-rust-lld" ,
125+ ui_test_name : None ,
105126 condition : cache. rust_lld ,
106127 ignore_reason : "ignored on targets without Rust's LLD" ,
107128 } ,
108129 Need {
109- names : & [ "needs-rust-lldb" ] ,
130+ compiletest_name : "needs-rust-lldb" ,
131+ ui_test_name : None ,
110132 condition : config. debugger != Some ( Debugger :: Lldb ) || config. lldb_native_rust ,
111133 ignore_reason : "ignored on targets without Rust's LLDB" ,
112134 } ,
113135 Need {
114- names : & [ "needs-i686-dlltool" ] ,
136+ compiletest_name : "needs-i686-dlltool" ,
137+ ui_test_name : None ,
115138 condition : cache. i686_dlltool ,
116139 ignore_reason : "ignored when dlltool for i686 is not present" ,
117140 } ,
118141 Need {
119- names : & [ "needs-x86_64-dlltool" ] ,
142+ compiletest_name : "needs-x86_64-dlltool" ,
143+ ui_test_name : None ,
120144 condition : cache. x86_64_dlltool ,
121145 ignore_reason : "ignored when dlltool for x86_64 is not present" ,
122146 } ,
123147 Need {
124- names : & [ "needs-dlltool" ] ,
148+ compiletest_name : "needs-dlltool" ,
149+ ui_test_name : None ,
125150 condition : cache. dlltool ,
126151 ignore_reason : "ignored when dlltool for the current architecture is not present" ,
127152 } ,
128153 Need {
129- names : & [ "needs-git-hash" ] ,
154+ compiletest_name : "needs-git-hash" ,
155+ ui_test_name : None ,
130156 condition : config. git_hash ,
131157 ignore_reason : "ignored when git hashes have been omitted for building" ,
132158 } ,
133159 Need {
134- names : & [ "needs-dynamic-linking" ] ,
160+ compiletest_name : "needs-dynamic-linking" ,
161+ ui_test_name : None ,
135162 condition : config. target_cfg ( ) . dynamic_linking ,
136163 ignore_reason : "ignored on targets without dynamic linking" ,
137164 } ,
138165 ] ;
139166
140- let ( name, comment) = match ln. split_once ( [ ':' , ' ' ] ) {
141- Some ( ( name, comment) ) => ( name, Some ( comment) ) ,
167+ let ln = comment. comment_str ( ) ;
168+ let ( name, args) = match ln. split_once ( [ ':' , ' ' ] ) {
169+ Some ( ( name, args) ) => ( name, Some ( args) ) ,
142170 None => ( ln, None ) ,
143171 } ;
144172
@@ -153,13 +181,13 @@ pub(super) fn handle_needs(
153181
154182 let mut found_valid = false ;
155183 for need in needs {
156- if need. names . contains ( & name ) {
184+ if need. matches_comment ( comment ) {
157185 if need. condition {
158186 found_valid = true ;
159187 break ;
160188 } else {
161189 return IgnoreDecision :: Ignore {
162- reason : if let Some ( comment) = comment {
190+ reason : if let Some ( comment) = args {
163191 format ! ( "{} ({comment})" , need. ignore_reason)
164192 } else {
165193 need. ignore_reason . into ( )
@@ -176,12 +204,25 @@ pub(super) fn handle_needs(
176204 }
177205}
178206
207+ #[ derive( Debug , Clone , Copy ) ]
179208struct Need {
180- names : & ' static [ & ' static str ] ,
209+ compiletest_name : & ' static str ,
210+ ui_test_name : Option < & ' static str > ,
181211 condition : bool ,
182212 ignore_reason : & ' static str ,
183213}
184214
215+ impl Need {
216+ fn matches_comment ( & self , comment : TestComment < ' _ > ) -> bool {
217+ match comment. comment ( ) {
218+ CommentKind :: Compiletest ( line) => line. starts_with ( self . compiletest_name ) ,
219+ CommentKind :: UiTest ( line) => {
220+ self . ui_test_name . is_some_and ( |ui_test_name| line. starts_with ( ui_test_name) )
221+ }
222+ }
223+ }
224+ }
225+
185226pub ( super ) struct CachedNeedsConditions {
186227 sanitizer_support : bool ,
187228 sanitizer_address : bool ,
0 commit comments