Skip to content

Commit 9849d6f

Browse files
committed
Add RUSTC_BOOTSTRAP=-1 to make rustc pretend as stable compiler
1 parent ec239b8 commit 9849d6f

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

compiler/rustc_feature/src/lib.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,19 @@ impl UnstableFeatures {
7474
// Returns whether `krate` should be counted as unstable
7575
let is_unstable_crate =
7676
|var: &str| krate.is_some_and(|name| var.split(',').any(|new_krate| new_krate == name));
77-
// `true` if we should enable unstable features for bootstrapping.
78-
let bootstrap =
79-
std::env::var("RUSTC_BOOTSTRAP").is_ok_and(|var| var == "1" || is_unstable_crate(&var));
80-
match (disable_unstable_features, bootstrap) {
81-
(_, true) => UnstableFeatures::Cheat,
82-
(true, _) => UnstableFeatures::Disallow,
83-
(false, _) => UnstableFeatures::Allow,
77+
78+
let bootstrap = std::env::var("RUSTC_BOOTSTRAP").ok();
79+
if let Some(ref val) = bootstrap {
80+
match val.as_str() {
81+
val if val == "1" || is_unstable_crate(val) => return UnstableFeatures::Cheat,
82+
// Hypnotize ourselves to so we are a stable compiler and thus don't allow any
83+
// unstable features.
84+
"-1" => return UnstableFeatures::Disallow,
85+
_ => {}
86+
}
8487
}
88+
89+
if disable_unstable_features { UnstableFeatures::Disallow } else { UnstableFeatures::Allow }
8590
}
8691

8792
pub fn is_nightly_build(&self) -> bool {

compiler/rustc_feature/src/tests.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ fn rustc_bootstrap_parsing() {
1818
assert!(!is_bootstrap("x,y,z", Some("a")));
1919
assert!(!is_bootstrap("x,y,z", None));
2020

21-
// this is technically a breaking change, but there are no stability guarantees for RUSTC_BOOTSTRAP
21+
// `RUSTC_BOOTSTRAP=0` is not recognized.
2222
assert!(!is_bootstrap("0", None));
23+
24+
// `RUSTC_BOOTSTRAP=-1` is force-stable, no unstable features allowed.
25+
let is_force_stable = |krate| {
26+
std::env::set_var("RUSTC_BOOTSTRAP", "-1");
27+
matches!(UnstableFeatures::from_environment(krate), UnstableFeatures::Disallow)
28+
};
29+
assert!(is_force_stable(None));
30+
// Does not support specifying any crate.
31+
assert!(is_force_stable(Some("x")));
32+
assert!(is_force_stable(Some("x,y,z")));
2333
}

compiler/rustc_feature/src/unstable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct EnabledLangFeature {
5454
pub stable_since: Option<Symbol>,
5555
}
5656

57-
/// Information abhout an enabled library feature.
57+
/// Information about an enabled library feature.
5858
#[derive(Debug, Copy, Clone)]
5959
pub struct EnabledLibFeature {
6060
pub gate_name: Symbol,

0 commit comments

Comments
 (0)