@@ -680,7 +680,8 @@ pub fn line_directive<'line>(
680
680
/// This is generated by collecting directives from ui tests and then extracting their directive
681
681
/// names. This is **not** an exhaustive list of all possible directives. Instead, this is a
682
682
/// best-effort approximation for diagnostics.
683
- const DIAGNOSTICS_DIRECTIVE_NAMES : & [ & str ] = & [
683
+ const KNOWN_DIRECTIVE_NAMES : & [ & str ] = & [
684
+ // tidy-alphabetical-start
684
685
"assembly-output" ,
685
686
"aux-build" ,
686
687
"aux-crate" ,
@@ -693,6 +694,7 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
693
694
"check-stdout" ,
694
695
"check-test-line-numbers-match" ,
695
696
"compile-flags" ,
697
+ "count" ,
696
698
"dont-check-compiler-stderr" ,
697
699
"dont-check-compiler-stdout" ,
698
700
"dont-check-failure-status" ,
@@ -716,6 +718,7 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
716
718
"ignore-compare-mode-polonius" ,
717
719
"ignore-cross-compile" ,
718
720
"ignore-debug" ,
721
+ "ignore-eabi" ,
719
722
"ignore-emscripten" ,
720
723
"ignore-endian-big" ,
721
724
"ignore-freebsd" ,
@@ -731,14 +734,30 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
731
734
"ignore-lldb" ,
732
735
"ignore-llvm-version" ,
733
736
"ignore-loongarch64" ,
737
+ "ignore-macabi" ,
734
738
"ignore-macos" ,
739
+ "ignore-mode-assembly" ,
740
+ "ignore-mode-codegen" ,
741
+ "ignore-mode-codegen-units" ,
735
742
"ignore-mode-coverage-map" ,
736
743
"ignore-mode-coverage-run" ,
744
+ "ignore-mode-debuginfo" ,
745
+ "ignore-mode-incremental" ,
746
+ "ignore-mode-js-doc-test" ,
747
+ "ignore-mode-mir-opt" ,
748
+ "ignore-mode-pretty" ,
749
+ "ignore-mode-run-make" ,
750
+ "ignore-mode-run-pass-valgrind" ,
751
+ "ignore-mode-rustdoc" ,
752
+ "ignore-mode-rustdoc-json" ,
753
+ "ignore-mode-ui" ,
754
+ "ignore-mode-ui-fulldeps" ,
737
755
"ignore-msp430" ,
738
756
"ignore-msvc" ,
739
757
"ignore-musl" ,
740
758
"ignore-netbsd" ,
741
759
"ignore-nightly" ,
760
+ "ignore-none" ,
742
761
"ignore-nto" ,
743
762
"ignore-nvptx64" ,
744
763
"ignore-openbsd" ,
@@ -750,35 +769,47 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
750
769
"ignore-spirv" ,
751
770
"ignore-stable" ,
752
771
"ignore-stage1" ,
772
+ "ignore-stage2" ,
753
773
"ignore-test" ,
774
+ "ignore-thumb" ,
754
775
"ignore-thumbv8m.base-none-eabi" ,
755
776
"ignore-thumbv8m.main-none-eabi" ,
777
+ "ignore-unix" ,
778
+ "ignore-unknown" ,
756
779
"ignore-uwp" ,
757
780
"ignore-vxworks" ,
781
+ "ignore-wasi" ,
758
782
"ignore-wasm" ,
759
783
"ignore-wasm32" ,
760
784
"ignore-wasm32-bare" ,
785
+ "ignore-wasm64" ,
761
786
"ignore-windows" ,
762
787
"ignore-windows-gnu" ,
788
+ "ignore-x32" ,
763
789
"ignore-x86" ,
790
+ "ignore-x86_64" ,
764
791
"ignore-x86_64-apple-darwin" ,
792
+ "ignore-x86_64-unknown-linux-gnu" ,
765
793
"incremental" ,
766
794
"known-bug" ,
767
795
"llvm-cov-flags" ,
768
796
"min-cdb-version" ,
769
797
"min-gdb-version" ,
770
798
"min-lldb-version" ,
771
799
"min-llvm-version" ,
800
+ "min-system-llvm-version" ,
772
801
"needs-asm-support" ,
773
802
"needs-dlltool" ,
774
803
"needs-dynamic-linking" ,
804
+ "needs-git-hash" ,
775
805
"needs-llvm-components" ,
776
806
"needs-profiler-support" ,
777
807
"needs-relocation-model-pic" ,
778
808
"needs-run-enabled" ,
779
809
"needs-rust-lldb" ,
780
810
"needs-sanitizer-address" ,
781
811
"needs-sanitizer-cfi" ,
812
+ "needs-sanitizer-dataflow" ,
782
813
"needs-sanitizer-hwaddress" ,
783
814
"needs-sanitizer-leak" ,
784
815
"needs-sanitizer-memory" ,
@@ -801,6 +832,7 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
801
832
"only-aarch64" ,
802
833
"only-arm" ,
803
834
"only-avr" ,
835
+ "only-beta" ,
804
836
"only-bpf" ,
805
837
"only-cdb" ,
806
838
"only-gnu" ,
@@ -818,13 +850,15 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
818
850
"only-riscv64" ,
819
851
"only-sparc" ,
820
852
"only-sparc64" ,
853
+ "only-stable" ,
821
854
"only-thumb" ,
822
855
"only-wasm32" ,
823
856
"only-wasm32-bare" ,
824
857
"only-windows" ,
825
858
"only-x86" ,
826
859
"only-x86_64" ,
827
860
"only-x86_64-fortanix-unknown-sgx" ,
861
+ "only-x86_64-pc-windows-gnu" ,
828
862
"only-x86_64-pc-windows-msvc" ,
829
863
"only-x86_64-unknown-linux-gnu" ,
830
864
"pp-exact" ,
@@ -846,6 +880,7 @@ const DIAGNOSTICS_DIRECTIVE_NAMES: &[&str] = &[
846
880
"unit-test" ,
847
881
"unset-exec-env" ,
848
882
"unset-rustc-env" ,
883
+ // tidy-alphabetical-end
849
884
] ;
850
885
851
886
/// The broken-down contents of a line containing a test header directive,
@@ -876,6 +911,22 @@ struct HeaderLine<'ln> {
876
911
directive : & ' ln str ,
877
912
}
878
913
914
+ pub ( crate ) struct CheckDirectiveResult < ' ln > {
915
+ is_known_directive : bool ,
916
+ directive_name : & ' ln str ,
917
+ }
918
+
919
+ // Returns `(is_known_directive, directive_name)`.
920
+ pub ( crate ) fn check_directive ( directive_ln : & str ) -> CheckDirectiveResult < ' _ > {
921
+ let directive_name =
922
+ directive_ln. split_once ( [ ':' , ' ' ] ) . map ( |( pre, _) | pre) . unwrap_or ( directive_ln) ;
923
+
924
+ CheckDirectiveResult {
925
+ is_known_directive : KNOWN_DIRECTIVE_NAMES . contains ( & directive_name) ,
926
+ directive_name : directive_ln,
927
+ }
928
+ }
929
+
879
930
fn iter_header (
880
931
mode : Mode ,
881
932
_suite : & str ,
@@ -915,6 +966,7 @@ fn iter_header(
915
966
let mut ln = String :: new ( ) ;
916
967
let mut line_number = 0 ;
917
968
969
+ // Match on error annotations like `//~ERROR`.
918
970
static REVISION_MAGIC_COMMENT_RE : Lazy < Regex > =
919
971
Lazy :: new ( || Regex :: new ( "//(\\ [.*\\ ])?~.*" ) . unwrap ( ) ) ;
920
972
@@ -933,9 +985,38 @@ fn iter_header(
933
985
if ln. starts_with ( "fn" ) || ln. starts_with ( "mod" ) {
934
986
return ;
935
987
936
- // First try to accept `ui_test` style comments
937
- } else if let Some ( ( header_revision, directive) ) = line_directive ( comment, ln) {
938
- it ( HeaderLine { line_number, original_line, header_revision, directive } ) ;
988
+ // First try to accept `ui_test` style comments (`//@`)
989
+ } else if let Some ( ( header_revision, non_revisioned_directive_line) ) =
990
+ line_directive ( comment, ln)
991
+ {
992
+ // Perform unknown directive check on Rust files.
993
+ if testfile. extension ( ) . map ( |e| e == "rs" ) . unwrap_or ( false ) {
994
+ let directive_ln = non_revisioned_directive_line. trim ( ) ;
995
+
996
+ let CheckDirectiveResult { is_known_directive, .. } = check_directive ( directive_ln) ;
997
+
998
+ if !is_known_directive {
999
+ * poisoned = true ;
1000
+
1001
+ eprintln ! (
1002
+ "error: detected unknown compiletest test directive `{}` in {}:{}" ,
1003
+ directive_ln,
1004
+ testfile. display( ) ,
1005
+ line_number,
1006
+ ) ;
1007
+
1008
+ return ;
1009
+ }
1010
+ }
1011
+
1012
+ it ( HeaderLine {
1013
+ line_number,
1014
+ original_line,
1015
+ header_revision,
1016
+ directive : non_revisioned_directive_line,
1017
+ } ) ;
1018
+ // Then we try to check for legacy-style candidates, which are not the magic ~ERROR family
1019
+ // error annotations.
939
1020
} else if !REVISION_MAGIC_COMMENT_RE . is_match ( ln) {
940
1021
let Some ( ( _, rest) ) = line_directive ( "//" , ln) else {
941
1022
continue ;
@@ -949,34 +1030,18 @@ fn iter_header(
949
1030
950
1031
let rest = rest. trim_start ( ) ;
951
1032
952
- for candidate in DIAGNOSTICS_DIRECTIVE_NAMES . iter ( ) {
953
- if rest. starts_with ( candidate) {
954
- let Some ( prefix_removed) = rest. strip_prefix ( candidate) else {
955
- // We have a comment that's *successfully* parsed as an legacy-style
956
- // directive. We emit an error here to warn the user.
957
- * poisoned = true ;
958
- eprintln ! (
959
- "error: detected legacy-style directives in compiletest test: {}:{}, please use `ui_test`-style directives `//@` instead:{:#?}" ,
960
- testfile. display( ) ,
961
- line_number,
962
- line_directive( "//" , ln) ,
963
- ) ;
964
- return ;
965
- } ;
1033
+ let CheckDirectiveResult { is_known_directive, directive_name } = check_directive ( rest) ;
966
1034
967
- if prefix_removed. starts_with ( [ ' ' , ':' ] ) {
968
- // We have a comment that's *successfully* parsed as an legacy-style
969
- // directive. We emit an error here to warn the user.
970
- * poisoned = true ;
971
- eprintln ! (
972
- "error: detected legacy-style directives in compiletest test: {}:{}, please use `ui_test`-style directives `//@` instead:{:#?}" ,
973
- testfile. display( ) ,
974
- line_number,
975
- line_directive( "//" , ln) ,
976
- ) ;
977
- return ;
978
- }
979
- }
1035
+ if is_known_directive {
1036
+ * poisoned = true ;
1037
+ eprintln ! (
1038
+ "error: detected legacy-style directive {} in compiletest test: {}:{}, please use `ui_test`-style directives `//@` instead: {:#?}" ,
1039
+ directive_name,
1040
+ testfile. display( ) ,
1041
+ line_number,
1042
+ line_directive( "//" , ln) ,
1043
+ ) ;
1044
+ return ;
980
1045
}
981
1046
}
982
1047
}
0 commit comments