Skip to content

Commit 240a4da

Browse files
authored
Rollup merge of #138692 - jieyouxu:reject-bool-lit-rev-names, r=wesleywiser
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. Closes #138663.
2 parents 928468c + bf37447 commit 240a4da

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

src/tools/compiletest/src/header.rs

+28-8
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,14 @@ fn iter_header(
924924

925925
impl Config {
926926
fn parse_and_update_revisions(&self, testfile: &Path, line: &str, existing: &mut Vec<String>) {
927-
const FORBIDDEN_REVISION_NAMES: [&str; 9] =
927+
const FORBIDDEN_REVISION_NAMES: [&str; 2] = [
928+
// `//@ revisions: true false` Implying `--cfg=true` and `--cfg=false` makes it very
929+
// weird for the test, since if the test writer wants a cfg of the same revision name
930+
// they'd have to use `cfg(r#true)` and `cfg(r#false)`.
931+
"true", "false",
932+
];
933+
934+
const FILECHECK_FORBIDDEN_REVISION_NAMES: [&str; 9] =
928935
["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"];
929936

930937
if let Some(raw) = self.parse_name_value_directive(line, "revisions") {
@@ -933,25 +940,38 @@ impl Config {
933940
}
934941

935942
let mut duplicates: HashSet<_> = existing.iter().cloned().collect();
936-
for revision in raw.split_whitespace().map(|r| r.to_string()) {
937-
if !duplicates.insert(revision.clone()) {
943+
for revision in raw.split_whitespace() {
944+
if !duplicates.insert(revision.to_string()) {
938945
panic!(
939946
"duplicate revision: `{}` in line `{}`: {}",
940947
revision,
941948
raw,
942949
testfile.display()
943950
);
944-
} else if matches!(self.mode, Mode::Assembly | Mode::Codegen | Mode::MirOpt)
945-
&& FORBIDDEN_REVISION_NAMES.contains(&revision.as_str())
951+
}
952+
953+
if FORBIDDEN_REVISION_NAMES.contains(&revision) {
954+
panic!(
955+
"revision name `{revision}` is not permitted: `{}` in line `{}`: {}",
956+
revision,
957+
raw,
958+
testfile.display()
959+
);
960+
}
961+
962+
if matches!(self.mode, Mode::Assembly | Mode::Codegen | Mode::MirOpt)
963+
&& FILECHECK_FORBIDDEN_REVISION_NAMES.contains(&revision)
946964
{
947965
panic!(
948-
"revision name `{revision}` is not permitted in a test suite that uses `FileCheck` annotations\n\
949-
as it is confusing when used as custom `FileCheck` prefix: `{revision}` in line `{}`: {}",
966+
"revision name `{revision}` is not permitted in a test suite that uses \
967+
`FileCheck` annotations as it is confusing when used as custom `FileCheck` \
968+
prefix: `{revision}` in line `{}`: {}",
950969
raw,
951970
testfile.display()
952971
);
953972
}
954-
existing.push(revision);
973+
974+
existing.push(revision.to_string());
955975
}
956976
}
957977
}

src/tools/compiletest/src/header/tests.rs

+7
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,13 @@ fn test_assembly_mode_forbidden_revisions() {
567567
parse_rs(&config, "//@ revisions: CHECK");
568568
}
569569

570+
#[test]
571+
#[should_panic(expected = "revision name `true` is not permitted")]
572+
fn test_forbidden_revisions() {
573+
let config = cfg().mode("ui").build();
574+
parse_rs(&config, "//@ revisions: true");
575+
}
576+
570577
#[test]
571578
#[should_panic(
572579
expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations"

0 commit comments

Comments
 (0)