@@ -5,9 +5,7 @@ use std::io::BufReader;
55use std:: io:: prelude:: * ;
66use std:: path:: { Path , PathBuf } ;
77use std:: process:: Command ;
8- use std:: sync:: OnceLock ;
98
10- use regex:: Regex ;
119use tracing:: * ;
1210
1311use crate :: common:: { Config , Debugger , FailMode , Mode , PassMode } ;
@@ -797,7 +795,6 @@ struct HeaderLine<'ln> {
797795
798796pub ( crate ) struct CheckDirectiveResult < ' ln > {
799797 is_known_directive : bool ,
800- directive_name : & ' ln str ,
801798 trailing_directive : Option < & ' ln str > ,
802799}
803800
@@ -832,11 +829,7 @@ pub(crate) fn check_directive<'a>(
832829 }
833830 . then_some ( trailing) ;
834831
835- CheckDirectiveResult {
836- is_known_directive : is_known ( & directive_name) ,
837- directive_name : directive_ln,
838- trailing_directive,
839- }
832+ CheckDirectiveResult { is_known_directive : is_known ( & directive_name) , trailing_directive }
840833}
841834
842835fn iter_header (
@@ -851,16 +844,17 @@ fn iter_header(
851844 return ;
852845 }
853846
854- // Coverage tests in coverage-run mode always have these extra directives,
855- // without needing to specify them manually in every test file.
856- // (Some of the comments below have been copied over from the old
857- // `tests/run-make/coverage-reports/Makefile`, which no longer exists.)
847+ // Coverage tests in coverage-run mode always have these extra directives, without needing to
848+ // specify them manually in every test file. (Some of the comments below have been copied over
849+ // from the old `tests/run-make/coverage-reports/Makefile`, which no longer exists.)
850+ //
851+ // FIXME(jieyouxu): I feel like there's a better way to do this, leaving for later.
858852 if mode == Mode :: CoverageRun {
859853 let extra_directives: & [ & str ] = & [
860854 "needs-profiler-support" ,
861- // FIXME(pietroalbini): this test currently does not work on cross-compiled
862- // targets because remote-test is not capable of sending back the *.profraw
863- // files generated by the LLVM instrumentation.
855+ // FIXME(pietroalbini): this test currently does not work on cross-compiled targets
856+ // because remote-test is not capable of sending back the *.profraw files generated by
857+ // the LLVM instrumentation.
864858 "ignore-cross-compile" ,
865859 ] ;
866860 // Process the extra implied directives, with a dummy line number of 0.
@@ -869,17 +863,13 @@ fn iter_header(
869863 }
870864 }
871865
866+ // NOTE(jieyouxu): once we get rid of `Makefile`s we can unconditionally check for `//@`.
872867 let comment = if testfile. extension ( ) . is_some_and ( |e| e == "rs" ) { "//@" } else { "#" } ;
873868
874869 let mut rdr = BufReader :: with_capacity ( 1024 , rdr) ;
875870 let mut ln = String :: new ( ) ;
876871 let mut line_number = 0 ;
877872
878- // Match on error annotations like `//~ERROR`.
879- static REVISION_MAGIC_COMMENT_RE : OnceLock < Regex > = OnceLock :: new ( ) ;
880- let revision_magic_comment_re =
881- REVISION_MAGIC_COMMENT_RE . get_or_init ( || Regex :: new ( "//(\\ [.*\\ ])?~.*" ) . unwrap ( ) ) ;
882-
883873 loop {
884874 line_number += 1 ;
885875 ln. clear ( ) ;
@@ -892,85 +882,62 @@ fn iter_header(
892882 // with a warm page cache. Maybe with a cold one.
893883 let original_line = & ln;
894884 let ln = ln. trim ( ) ;
885+
886+ // Assume that any directives will be found before the first module or function. This
887+ // doesn't seem to be an optimization with a warm page cache. Maybe with a cold one.
888+ // FIXME(jieyouxu): this will cause `//@` directives in the rest of the test file to
889+ // not be checked.
895890 if ln. starts_with ( "fn" ) || ln. starts_with ( "mod" ) {
896891 return ;
892+ }
897893
898- // First try to accept `ui_test` style comments (`//@`)
899- } else if let Some ( ( header_revision, non_revisioned_directive_line) ) =
900- line_directive ( comment, ln)
901- {
902- // Perform unknown directive check on Rust files.
903- if testfile. extension ( ) . map ( |e| e == "rs" ) . unwrap_or ( false ) {
904- let directive_ln = non_revisioned_directive_line. trim ( ) ;
905-
906- let CheckDirectiveResult { is_known_directive, trailing_directive, .. } =
907- check_directive ( directive_ln, mode, ln) ;
908-
909- if !is_known_directive {
910- * poisoned = true ;
911-
912- eprintln ! (
913- "error: detected unknown compiletest test directive `{}` in {}:{}" ,
914- directive_ln,
915- testfile. display( ) ,
916- line_number,
917- ) ;
918-
919- return ;
920- }
894+ let Some ( ( header_revision, non_revisioned_directive_line) ) = line_directive ( comment, ln)
895+ else {
896+ continue ;
897+ } ;
921898
922- if let Some ( trailing_directive) = & trailing_directive {
923- * poisoned = true ;
899+ // Perform unknown directive check on Rust files.
900+ if testfile. extension ( ) . map ( |e| e == "rs" ) . unwrap_or ( false ) {
901+ let directive_ln = non_revisioned_directive_line. trim ( ) ;
924902
925- eprintln ! (
926- "error: detected trailing compiletest test directive `{}` in {}:{}\n \
927- help: put the trailing directive in it's own line: `//@ {}`",
928- trailing_directive,
929- testfile. display( ) ,
930- line_number,
931- trailing_directive,
932- ) ;
903+ let CheckDirectiveResult { is_known_directive, trailing_directive } =
904+ check_directive ( directive_ln, mode, ln) ;
933905
934- return ;
935- }
936- }
906+ if !is_known_directive {
907+ * poisoned = true ;
937908
938- it ( HeaderLine {
939- line_number,
940- original_line,
941- header_revision,
942- directive : non_revisioned_directive_line,
943- } ) ;
944- // Then we try to check for legacy-style candidates, which are not the magic ~ERROR family
945- // error annotations.
946- } else if !revision_magic_comment_re. is_match ( ln) {
947- let Some ( ( _, rest) ) = line_directive ( "//" , ln) else {
948- continue ;
949- } ;
909+ eprintln ! (
910+ "error: detected unknown compiletest test directive `{}` in {}:{}" ,
911+ directive_ln,
912+ testfile. display( ) ,
913+ line_number,
914+ ) ;
950915
951- if rest. trim_start ( ) . starts_with ( ':' ) {
952- // This is likely a markdown link:
953- // `[link_name]: https://example.org`
954- continue ;
916+ return ;
955917 }
956918
957- let rest = rest. trim_start ( ) ;
958-
959- let CheckDirectiveResult { is_known_directive, directive_name, .. } =
960- check_directive ( rest, mode, ln) ;
961-
962- if is_known_directive {
919+ if let Some ( trailing_directive) = & trailing_directive {
963920 * poisoned = true ;
921+
964922 eprintln ! (
965- "error: detected legacy-style directive {} in compiletest test: {}:{}, please use `ui_test`-style directives `//@` instead: {:#?}" ,
966- directive_name,
923+ "error: detected trailing compiletest test directive `{}` in {}:{}\n \
924+ help: put the trailing directive in it's own line: `//@ {}`",
925+ trailing_directive,
967926 testfile. display( ) ,
968927 line_number,
969- line_directive ( "//" , ln ) ,
928+ trailing_directive ,
970929 ) ;
930+
971931 return ;
972932 }
973933 }
934+
935+ it ( HeaderLine {
936+ line_number,
937+ original_line,
938+ header_revision,
939+ directive : non_revisioned_directive_line,
940+ } ) ;
974941 }
975942}
976943
0 commit comments