diff options
| author | Jieyou Xu <jieyouxu@outlook.com> | 2025-03-19 14:43:51 +0800 |
|---|---|---|
| committer | Jieyou Xu <jieyouxu@outlook.com> | 2025-03-19 15:02:57 +0800 |
| commit | bf374475c87f23690a0228ec945b48908786ff38 (patch) | |
| tree | b950facd984f4beaf7e477e2f1468b489250ed65 /src | |
| parent | 75530e9f72a1990ed2305e16fd51d02f47048f12 (diff) | |
| download | rust-bf374475c87f23690a0228ec945b48908786ff38.tar.gz rust-bf374475c87f23690a0228ec945b48908786ff38.zip | |
Reject `{true,false}` as revision names
Because they would imply `--cfg={true,false}` otherwise, and the test
writer has to use `cfg(r#true)` and `cfg(r#false)` in the test.
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/compiletest/src/header.rs | 36 | ||||
| -rw-r--r-- | src/tools/compiletest/src/header/tests.rs | 7 |
2 files changed, 35 insertions, 8 deletions
diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 7675e13990d..fb2b90d74bd 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -924,7 +924,14 @@ fn iter_header( impl Config { fn parse_and_update_revisions(&self, testfile: &Path, line: &str, existing: &mut Vec<String>) { - const FORBIDDEN_REVISION_NAMES: [&str; 9] = + const FORBIDDEN_REVISION_NAMES: [&str; 2] = [ + // `//@ revisions: true false` Implying `--cfg=true` and `--cfg=false` makes it very + // weird for the test, since if the test writer wants a cfg of the same revision name + // they'd have to use `cfg(r#true)` and `cfg(r#false)`. + "true", "false", + ]; + + const FILECHECK_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") { @@ -933,25 +940,38 @@ impl Config { } let mut duplicates: HashSet<_> = existing.iter().cloned().collect(); - for revision in raw.split_whitespace().map(|r| r.to_string()) { - if !duplicates.insert(revision.clone()) { + for revision in raw.split_whitespace() { + if !duplicates.insert(revision.to_string()) { panic!( "duplicate revision: `{}` in line `{}`: {}", revision, raw, testfile.display() ); - } else if matches!(self.mode, Mode::Assembly | Mode::Codegen | Mode::MirOpt) - && FORBIDDEN_REVISION_NAMES.contains(&revision.as_str()) + } + + if FORBIDDEN_REVISION_NAMES.contains(&revision) { + panic!( + "revision name `{revision}` is not permitted: `{}` in line `{}`: {}", + revision, + raw, + testfile.display() + ); + } + + if matches!(self.mode, Mode::Assembly | Mode::Codegen | Mode::MirOpt) + && FILECHECK_FORBIDDEN_REVISION_NAMES.contains(&revision) { 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 `{}`: {}", + "revision name `{revision}` is not permitted in a test suite that uses \ + `FileCheck` annotations as it is confusing when used as custom `FileCheck` \ + prefix: `{revision}` in line `{}`: {}", raw, testfile.display() ); } - existing.push(revision); + + existing.push(revision.to_string()); } } } diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index 007318be7cc..4d90f152ee2 100644 --- a/src/tools/compiletest/src/header/tests.rs +++ b/src/tools/compiletest/src/header/tests.rs @@ -568,6 +568,13 @@ fn test_assembly_mode_forbidden_revisions() { } #[test] +#[should_panic(expected = "revision name `true` is not permitted")] +fn test_forbidden_revisions() { + let config = cfg().mode("ui").build(); + parse_rs(&config, "//@ revisions: true"); +} + +#[test] #[should_panic( expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations" )] |
