@@ -55,7 +55,7 @@ impl EarlyProps {
55
55
& mut poisoned,
56
56
testfile,
57
57
rdr,
58
- & mut |_ , _ , ln, _ | {
58
+ & mut |HeaderLine { directive : ln, .. } | {
59
59
config. push_name_value_directive ( ln, directives:: AUX_BUILD , & mut props. aux , |r| {
60
60
r. trim ( ) . to_string ( )
61
61
} ) ;
@@ -330,8 +330,8 @@ impl TestProps {
330
330
& mut poisoned,
331
331
testfile,
332
332
file,
333
- & mut |revision , _ , ln, _ | {
334
- if revision . is_some ( ) && revision != cfg {
333
+ & mut |HeaderLine { header_revision , directive : ln, .. } | {
334
+ if header_revision . is_some ( ) && header_revision != cfg {
335
335
return ;
336
336
}
337
337
@@ -672,17 +672,6 @@ pub fn line_directive<'line>(
672
672
}
673
673
}
674
674
675
- fn iter_header < R : Read > (
676
- mode : Mode ,
677
- suite : & str ,
678
- poisoned : & mut bool ,
679
- testfile : & Path ,
680
- rdr : R ,
681
- it : & mut dyn FnMut ( Option < & str > , & str , & str , usize ) ,
682
- ) {
683
- iter_header_extra ( mode, suite, poisoned, testfile, rdr, & [ ] , it)
684
- }
685
-
686
675
/// This is generated by collecting directives from ui tests and then extracting their directive
687
676
/// names. This is **not** an exhaustive list of all possible directives. Instead, this is a
688
677
/// best-effort approximation for diagnostics.
@@ -801,23 +790,49 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
801
790
"unset-rustc-env" ,
802
791
] ;
803
792
804
- fn iter_header_extra (
793
+ /// Arguments passed to the callback in [`iter_header`].
794
+ struct HeaderLine < ' ln > {
795
+ /// Contents of the square brackets preceding this header, if present.
796
+ header_revision : Option < & ' ln str > ,
797
+ /// Raw line from the test file, including comment prefix and any revision.
798
+ original_line : & ' ln str ,
799
+ /// Remainder of the directive line, after the initial comment prefix
800
+ /// (`//` or `//@` or `#`) and revision (if any) have been stripped.
801
+ directive : & ' ln str ,
802
+ line_number : usize ,
803
+ }
804
+
805
+ fn iter_header (
805
806
mode : Mode ,
806
807
suite : & str ,
807
808
poisoned : & mut bool ,
808
809
testfile : & Path ,
809
810
rdr : impl Read ,
810
- extra_directives : & [ & str ] ,
811
- it : & mut dyn FnMut ( Option < & str > , & str , & str , usize ) ,
811
+ it : & mut dyn FnMut ( HeaderLine < ' _ > ) ,
812
812
) {
813
813
if testfile. is_dir ( ) {
814
814
return ;
815
815
}
816
816
817
- // Process any extra directives supplied by the caller (e.g. because they
818
- // are implied by the test mode), with a dummy line number of 0.
819
- for directive in extra_directives {
820
- it ( None , directive, directive, 0 ) ;
817
+ // Coverage tests in coverage-run mode always have these extra directives,
818
+ // without needing to specify them manually in every test file.
819
+ // (Some of the comments below have been copied over from the old
820
+ // `tests/run-make/coverage-reports/Makefile`, which no longer exists.)
821
+ if mode == Mode :: CoverageRun {
822
+ let extra_directives: & [ & str ] = & [
823
+ "needs-profiler-support" ,
824
+ // FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works
825
+ // properly. Since we only have GCC on the CI ignore the test for now.
826
+ "ignore-windows-gnu" ,
827
+ // FIXME(pietroalbini): this test currently does not work on cross-compiled
828
+ // targets because remote-test is not capable of sending back the *.profraw
829
+ // files generated by the LLVM instrumentation.
830
+ "ignore-cross-compile" ,
831
+ ] ;
832
+ // Process the extra implied directives, with a dummy line number of 0.
833
+ for directive in extra_directives {
834
+ it ( HeaderLine { header_revision : None , original_line : "" , directive, line_number : 0 } ) ;
835
+ }
821
836
}
822
837
823
838
let comment = if testfile. extension ( ) . is_some_and ( |e| e == "rs" ) {
@@ -843,14 +858,14 @@ fn iter_header_extra(
843
858
// Assume that any directives will be found before the first
844
859
// module or function. This doesn't seem to be an optimization
845
860
// with a warm page cache. Maybe with a cold one.
846
- let orig_ln = & ln;
861
+ let original_line = & ln;
847
862
let ln = ln. trim ( ) ;
848
863
if ln. starts_with ( "fn" ) || ln. starts_with ( "mod" ) {
849
864
return ;
850
865
851
866
// First try to accept `ui_test` style comments
852
- } else if let Some ( ( lncfg , ln ) ) = line_directive ( comment, ln) {
853
- it ( lncfg , orig_ln , ln , line_number) ;
867
+ } else if let Some ( ( header_revision , directive ) ) = line_directive ( comment, ln) {
868
+ it ( HeaderLine { header_revision , original_line , directive , line_number } ) ;
854
869
} else if mode == Mode :: Ui && suite == "ui" && !REVISION_MAGIC_COMMENT_RE . is_match ( ln) {
855
870
let Some ( ( _, rest) ) = line_directive ( "//" , ln) else {
856
871
continue ;
@@ -1150,37 +1165,16 @@ pub fn make_test_description<R: Read>(
1150
1165
let mut ignore_message = None ;
1151
1166
let mut should_fail = false ;
1152
1167
1153
- let extra_directives: & [ & str ] = match config. mode {
1154
- // The coverage-run tests are treated as having these extra directives,
1155
- // without needing to specify them manually in every test file.
1156
- // (Some of the comments below have been copied over from
1157
- // `tests/run-make/coverage-reports/Makefile`, which no longer exists.)
1158
- Mode :: CoverageRun => {
1159
- & [
1160
- "needs-profiler-support" ,
1161
- // FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works
1162
- // properly. Since we only have GCC on the CI ignore the test for now.
1163
- "ignore-windows-gnu" ,
1164
- // FIXME(pietroalbini): this test currently does not work on cross-compiled
1165
- // targets because remote-test is not capable of sending back the *.profraw
1166
- // files generated by the LLVM instrumentation.
1167
- "ignore-cross-compile" ,
1168
- ]
1169
- }
1170
- _ => & [ ] ,
1171
- } ;
1172
-
1173
1168
let mut local_poisoned = false ;
1174
1169
1175
- iter_header_extra (
1170
+ iter_header (
1176
1171
config. mode ,
1177
1172
& config. suite ,
1178
1173
& mut local_poisoned,
1179
1174
path,
1180
1175
src,
1181
- extra_directives,
1182
- & mut |revision, og_ln, ln, line_number| {
1183
- if revision. is_some ( ) && revision != cfg {
1176
+ & mut |HeaderLine { header_revision, original_line, directive : ln, line_number } | {
1177
+ if header_revision. is_some ( ) && header_revision != cfg {
1184
1178
return ;
1185
1179
}
1186
1180
@@ -1204,7 +1198,7 @@ pub fn make_test_description<R: Read>(
1204
1198
} ;
1205
1199
}
1206
1200
1207
- if let Some ( ( _, post) ) = og_ln . trim_start ( ) . split_once ( "//" ) {
1201
+ if let Some ( ( _, post) ) = original_line . trim_start ( ) . split_once ( "//" ) {
1208
1202
let post = post. trim_start ( ) ;
1209
1203
if post. starts_with ( "ignore-tidy" )
1210
1204
&& config. mode == Mode :: Ui
0 commit comments