about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorUrgau <urgau@numericable.fr>2024-04-07 00:33:37 +0200
committerUrgau <urgau@numericable.fr>2024-05-04 11:30:38 +0200
commitd4e26fbb5301b465a037c4d2ff54024ebd7f73d8 (patch)
treed88675775f0531d394efd16a5906d9440b30875f /src
parent517374150cfb48e907aec059f3639eba3a9c1e1c (diff)
downloadrust-d4e26fbb5301b465a037c4d2ff54024ebd7f73d8.tar.gz
rust-d4e26fbb5301b465a037c4d2ff54024ebd7f73d8.zip
compiletest: add enable-by-default check-cfg
Diffstat (limited to 'src')
-rw-r--r--src/tools/compiletest/src/runtest.rs25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index 0a861d62c37..1d69ed59859 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -1028,12 +1028,31 @@ impl<'test> TestCx<'test> {
     }
 
     fn set_revision_flags(&self, cmd: &mut Command) {
+        // Normalize revisions to be lowercase and replace `-`s with `_`s.
+        // Otherwise the `--cfg` flag is not valid.
+        let normalize_revision = |revision: &str| revision.to_lowercase().replace("-", "_");
+
         if let Some(revision) = self.revision {
-            // Normalize revisions to be lowercase and replace `-`s with `_`s.
-            // Otherwise the `--cfg` flag is not valid.
-            let normalized_revision = revision.to_lowercase().replace("-", "_");
+            let normalized_revision = normalize_revision(revision);
             cmd.args(&["--cfg", &normalized_revision]);
         }
+
+        if !self.props.no_auto_check_cfg {
+            let mut check_cfg = String::with_capacity(25);
+
+            // Generate `cfg(FALSE, REV1, ..., REVN)` (for all possible revisions)
+            //
+            // For compatibility reason we consider the `FALSE` cfg to be expected
+            // since it is extensively used in the testsuite.
+            check_cfg.push_str("cfg(FALSE");
+            for revision in &self.props.revisions {
+                check_cfg.push_str(",");
+                check_cfg.push_str(&normalize_revision(&revision));
+            }
+            check_cfg.push_str(")");
+
+            cmd.args(&["--check-cfg", &check_cfg]);
+        }
     }
 
     fn typecheck_source(&self, src: String) -> ProcRes {