@@ -55,7 +55,7 @@ impl EarlyProps {
5555 & mut poisoned,
5656 testfile,
5757 rdr,
58- & mut |_ , _ , ln, _ | {
58+ & mut |HeaderLine { directive : ln, .. } | {
5959 config. push_name_value_directive ( ln, directives:: AUX_BUILD , & mut props. aux , |r| {
6060 r. trim ( ) . to_string ( )
6161 } ) ;
@@ -330,8 +330,8 @@ impl TestProps {
330330 & mut poisoned,
331331 testfile,
332332 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 {
335335 return ;
336336 }
337337
@@ -672,17 +672,6 @@ pub fn line_directive<'line>(
672672 }
673673}
674674
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-
686675/// This is generated by collecting directives from ui tests and then extracting their directive
687676/// names. This is **not** an exhaustive list of all possible directives. Instead, this is a
688677/// best-effort approximation for diagnostics.
@@ -801,23 +790,49 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
801790 "unset-rustc-env" ,
802791] ;
803792
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 (
805806 mode : Mode ,
806807 suite : & str ,
807808 poisoned : & mut bool ,
808809 testfile : & Path ,
809810 rdr : impl Read ,
810- extra_directives : & [ & str ] ,
811- it : & mut dyn FnMut ( Option < & str > , & str , & str , usize ) ,
811+ it : & mut dyn FnMut ( HeaderLine < ' _ > ) ,
812812) {
813813 if testfile. is_dir ( ) {
814814 return ;
815815 }
816816
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+ }
821836 }
822837
823838 let comment = if testfile. extension ( ) . is_some_and ( |e| e == "rs" ) {
@@ -843,14 +858,14 @@ fn iter_header_extra(
843858 // Assume that any directives will be found before the first
844859 // module or function. This doesn't seem to be an optimization
845860 // with a warm page cache. Maybe with a cold one.
846- let orig_ln = & ln;
861+ let original_line = & ln;
847862 let ln = ln. trim ( ) ;
848863 if ln. starts_with ( "fn" ) || ln. starts_with ( "mod" ) {
849864 return ;
850865
851866 // 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 } ) ;
854869 } else if mode == Mode :: Ui && suite == "ui" && !REVISION_MAGIC_COMMENT_RE . is_match ( ln) {
855870 let Some ( ( _, rest) ) = line_directive ( "//" , ln) else {
856871 continue ;
@@ -1150,37 +1165,16 @@ pub fn make_test_description<R: Read>(
11501165 let mut ignore_message = None ;
11511166 let mut should_fail = false ;
11521167
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-
11731168 let mut local_poisoned = false ;
11741169
1175- iter_header_extra (
1170+ iter_header (
11761171 config. mode ,
11771172 & config. suite ,
11781173 & mut local_poisoned,
11791174 path,
11801175 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 {
11841178 return ;
11851179 }
11861180
@@ -1204,7 +1198,7 @@ pub fn make_test_description<R: Read>(
12041198 } ;
12051199 }
12061200
1207- if let Some ( ( _, post) ) = og_ln . trim_start ( ) . split_once ( "//" ) {
1201+ if let Some ( ( _, post) ) = original_line . trim_start ( ) . split_once ( "//" ) {
12081202 let post = post. trim_start ( ) ;
12091203 if post. starts_with ( "ignore-tidy" )
12101204 && config. mode == Mode :: Ui
0 commit comments