about summary refs log tree commit diff
path: root/compiler/rustc_feature/src/lib.rs
diff options
context:
space:
mode:
authorJieyou Xu <jieyouxu@outlook.com>2024-11-13 17:55:25 +0800
committerJieyou Xu <jieyouxu@outlook.com>2024-11-17 19:59:52 +0800
commit202caa7c57f635c481670037dc52735635ec2f82 (patch)
tree5ccc3b2c79d4b2e0240cf55d7923971afa357e59 /compiler/rustc_feature/src/lib.rs
parent46e8d20301cb4abe91ab0a4bea43bb085e1d4e4a (diff)
downloadrust-202caa7c57f635c481670037dc52735635ec2f82.tar.gz
rust-202caa7c57f635c481670037dc52735635ec2f82.zip
Add `RUSTC_BOOTSTRAP=-1` to make rustc pretend as stable compiler
Diffstat (limited to 'compiler/rustc_feature/src/lib.rs')
-rw-r--r--compiler/rustc_feature/src/lib.rs19
1 files changed, 12 insertions, 7 deletions
diff --git a/compiler/rustc_feature/src/lib.rs b/compiler/rustc_feature/src/lib.rs
index 9f42d3ec45c..5d27b8f542c 100644
--- a/compiler/rustc_feature/src/lib.rs
+++ b/compiler/rustc_feature/src/lib.rs
@@ -74,14 +74,19 @@ impl UnstableFeatures {
         // Returns whether `krate` should be counted as unstable
         let is_unstable_crate =
             |var: &str| krate.is_some_and(|name| var.split(',').any(|new_krate| new_krate == name));
-        // `true` if we should enable unstable features for bootstrapping.
-        let bootstrap =
-            std::env::var("RUSTC_BOOTSTRAP").is_ok_and(|var| var == "1" || is_unstable_crate(&var));
-        match (disable_unstable_features, bootstrap) {
-            (_, true) => UnstableFeatures::Cheat,
-            (true, _) => UnstableFeatures::Disallow,
-            (false, _) => UnstableFeatures::Allow,
+
+        let bootstrap = std::env::var("RUSTC_BOOTSTRAP").ok();
+        if let Some(val) = bootstrap.as_deref() {
+            match val {
+                val if val == "1" || is_unstable_crate(val) => return UnstableFeatures::Cheat,
+                // Hypnotize ourselves so that we think we are a stable compiler and thus don't
+                // allow any unstable features.
+                "-1" => return UnstableFeatures::Disallow,
+                _ => {}
+            }
         }
+
+        if disable_unstable_features { UnstableFeatures::Disallow } else { UnstableFeatures::Allow }
     }
 
     pub fn is_nightly_build(&self) -> bool {