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