@@ -653,6 +653,124 @@ fn iter_header<R: Read>(
653653 iter_header_extra ( mode, poisoned, testfile, rdr, & [ ] , it)
654654}
655655
656+ /// This is generated by collecting directives from ui tests and then extracting their directive
657+ /// names. This is **not** an exhaustive list of all possible directives. Instead, this is a
658+ /// best-effort approximation for diagnostics.
659+ const DIAGNOSTICS_DIRECTIVE_NAMES : & [ & str ] = & [
660+ "aux-build" ,
661+ "aux-crate" ,
662+ "build-fail" ,
663+ "build-pass" ,
664+ "check-fail" ,
665+ "check-pass" ,
666+ "check-run-results" ,
667+ "check-stdout" ,
668+ "compile-flags" ,
669+ "dont-check-compiler-stderr" ,
670+ "dont-check-compiler-stdout" ,
671+ "dont-check-failure-status" ,
672+ "edition" ,
673+ "error-pattern" ,
674+ "exec-env" ,
675+ "failure-status" ,
676+ "forbid-output" ,
677+ "force-host" ,
678+ "ignore-32bit" ,
679+ "ignore-64bit" ,
680+ "ignore-aarch64" ,
681+ "ignore-aarch64-unknown-linux-gnu" ,
682+ "ignore-android" ,
683+ "ignore-arm" ,
684+ "ignore-compare-mode-next-solver" ,
685+ "ignore-compare-mode-polonius" ,
686+ "ignore-cross-compile" ,
687+ "ignore-debug" ,
688+ "ignore-emscripten" ,
689+ "ignore-endian-big" ,
690+ "ignore-freebsd" ,
691+ "ignore-fuchsia" ,
692+ "ignore-gnu" ,
693+ "ignore-haiku" ,
694+ "ignore-horizon" ,
695+ "ignore-i686-pc-windows-msvc" ,
696+ "ignore-ios" ,
697+ "ignore-llvm-version" ,
698+ "ignore-macos" ,
699+ "ignore-msvc" ,
700+ "ignore-musl" ,
701+ "ignore-netbsd" ,
702+ "ignore-nightly" ,
703+ "ignore-nto" ,
704+ "ignore-nvptx64" ,
705+ "ignore-openbsd" ,
706+ "ignore-pass" ,
707+ "ignore-sgx" ,
708+ "ignore-spirv" ,
709+ "ignore-test" ,
710+ "ignore-thumbv8m.base-none-eabi" ,
711+ "ignore-thumbv8m.main-none-eabi" ,
712+ "ignore-uwp" ,
713+ "ignore-vxworks" ,
714+ "ignore-wasm" ,
715+ "ignore-wasm32" ,
716+ "ignore-wasm32-bare" ,
717+ "ignore-windows" ,
718+ "ignore-x86" ,
719+ "incremental" ,
720+ "known-bug" ,
721+ "min-llvm-version" ,
722+ "needs-asm-support" ,
723+ "needs-dlltool" ,
724+ "needs-dynamic-linking" ,
725+ "needs-llvm-components" ,
726+ "needs-profiler-support" ,
727+ "needs-relocation-model-pic" ,
728+ "needs-run-enabled" ,
729+ "needs-sanitizer-address" ,
730+ "needs-sanitizer-cfi" ,
731+ "needs-sanitizer-hwaddress" ,
732+ "needs-sanitizer-leak" ,
733+ "needs-sanitizer-memory" ,
734+ "needs-sanitizer-support" ,
735+ "needs-sanitizer-thread" ,
736+ "needs-unwind" ,
737+ "needs-xray" ,
738+ "no-prefer-dynamic" ,
739+ "normalize-stderr-32bit" ,
740+ "normalize-stderr-64bit" ,
741+ "normalize-stderr-test" ,
742+ "normalize-stdout-test" ,
743+ "only-32bit" ,
744+ "only-64bit" ,
745+ "only-aarch64" ,
746+ "only-gnu" ,
747+ "only-i686-pc-windows-msvc" ,
748+ "only-linux" ,
749+ "only-macos" ,
750+ "only-msvc" ,
751+ "only-nightly" ,
752+ "only-wasm32" ,
753+ "only-windows" ,
754+ "only-x86" ,
755+ "only-x86_64" ,
756+ "only-x86_64-pc-windows-msvc" ,
757+ "only-x86_64-unknown-linux-gnu" ,
758+ "pp-exact" ,
759+ "pretty-expanded" ,
760+ "regex-error-pattern" ,
761+ "remap-src-base" ,
762+ "revisions" ,
763+ "run-fail" ,
764+ "run-flags" ,
765+ "run-pass" ,
766+ "run-rustfix" ,
767+ "rustc-env" ,
768+ "rustfix-only-machine-applicable" ,
769+ "should-fail" ,
770+ "stderr-per-bitwidth" ,
771+ "unset-rustc-env" ,
772+ ] ;
773+
656774fn iter_header_extra (
657775 mode : Mode ,
658776 poisoned : & mut bool ,
@@ -681,7 +799,7 @@ fn iter_header_extra(
681799 let mut ln = String :: new ( ) ;
682800 let mut line_number = 0 ;
683801
684- let revision_magic_comment = Regex :: new ( "//(\\ [.*\\ ])~.*" ) . unwrap ( ) ;
802+ let revision_magic_comment = Regex :: new ( "//(\\ [.*\\ ])? ~.*" ) . unwrap ( ) ;
685803
686804 loop {
687805 line_number += 1 ;
@@ -701,20 +819,33 @@ fn iter_header_extra(
701819 // First try to accept `ui_test` style comments
702820 } else if let Some ( ( lncfg, ln) ) = line_directive ( comment, ln) {
703821 it ( lncfg, orig_ln, ln, line_number) ;
704- } else if mode == Mode :: Ui
705- && !revision_magic_comment. is_match ( ln)
706- && matches ! ( line_directive( "//" , ln) , Some ( ( Some ( _) , _) ) )
707- {
708- // We have a comment that's *successfully* parsed as an legacy-style directive.
709- // We emit an error here to warn the user.
710- * poisoned = true ;
711- eprintln ! (
712- "error: detected legacy-style directives in ui test: {}:{}, please use `ui_test`-style directives `//@` instead:{:#?}" ,
713- testfile. display( ) ,
714- line_number,
715- line_directive( "//" , ln) ,
716- ) ;
717- return ;
822+ } else if mode == Mode :: Ui && !revision_magic_comment. is_match ( ln) {
823+ let Some ( ( _, rest) ) = line_directive ( "//" , ln) else {
824+ continue ;
825+ } ;
826+
827+ if rest. trim_start ( ) . starts_with ( ':' ) {
828+ // This is likely a markdown link:
829+ // `[link_name]: https://example.org`
830+ continue ;
831+ }
832+
833+ let rest = rest. trim_start ( ) ;
834+
835+ for candidate in DIAGNOSTICS_DIRECTIVE_NAMES . iter ( ) {
836+ if rest. starts_with ( candidate) {
837+ // We have a comment that's *successfully* parsed as an legacy-style directive.
838+ // We emit an error here to warn the user.
839+ * poisoned = true ;
840+ eprintln ! (
841+ "error: detected legacy-style directives in ui test: {}:{}, please use `ui_test`-style directives `//@` instead:{:#?}" ,
842+ testfile. display( ) ,
843+ line_number,
844+ line_directive( "//" , ln) ,
845+ ) ;
846+ return ;
847+ }
848+ }
718849 }
719850 }
720851}
0 commit comments