diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 48149e3b897e1..8c96554738e68 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -934,6 +934,9 @@ fn iter_header( impl Config { fn parse_and_update_revisions(&self, testfile: &Path, line: &str, existing: &mut Vec) { + const FORBIDDEN_REVISION_NAMES: [&str; 9] = + ["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"]; + if let Some(raw) = self.parse_name_value_directive(line, "revisions") { if self.mode == Mode::RunMake { panic!("`run-make` tests do not support revisions: {}", testfile.display()); @@ -948,6 +951,15 @@ impl Config { raw, testfile.display() ); + } else if matches!(self.mode, Mode::Assembly | Mode::Codegen | Mode::MirOpt) + && FORBIDDEN_REVISION_NAMES.contains(&revision.as_str()) + { + panic!( + "revision name `{revision}` is not permitted in a test suite that uses `FileCheck` annotations\n\ + as it is confusing when used as custom `FileCheck` prefix: `{revision}` in line `{}`: {}", + raw, + testfile.display() + ); } existing.push(revision); } diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index 618b66dfd4cb6..25bb1a5f42882 100644 --- a/src/tools/compiletest/src/header/tests.rs +++ b/src/tools/compiletest/src/header/tests.rs @@ -553,6 +553,59 @@ fn test_duplicate_revisions() { parse_rs(&config, "//@ revisions: rpass1 rpass1"); } +#[test] +#[should_panic( + expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations" +)] +fn test_assembly_mode_forbidden_revisions() { + let config = cfg().mode("assembly").build(); + parse_rs(&config, "//@ revisions: CHECK"); +} + +#[test] +#[should_panic( + expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations" +)] +fn test_codegen_mode_forbidden_revisions() { + let config = cfg().mode("codegen").build(); + parse_rs(&config, "//@ revisions: CHECK"); +} + +#[test] +#[should_panic( + expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations" +)] +fn test_miropt_mode_forbidden_revisions() { + let config = cfg().mode("mir-opt").build(); + parse_rs(&config, "//@ revisions: CHECK"); +} + +#[test] +fn test_forbidden_revisions_allowed_in_non_filecheck_dir() { + let revisions = ["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"]; + let modes = [ + "pretty", + "debuginfo", + "rustdoc", + "rustdoc-json", + "codegen-units", + "incremental", + "ui", + "js-doc-test", + "coverage-map", + "coverage-run", + "crashes", + ]; + + for rev in revisions { + let content = format!("//@ revisions: {rev}"); + for mode in modes { + let config = cfg().mode(mode).build(); + parse_rs(&config, &content); + } + } +} + #[test] fn ignore_arch() { let archs = [